def test_reset_environment(self): """Tests that reset_environment() works as intended.""" variable = 'NEW_VARIABLE' # Check that the test's assumptions are correct. self.assertNotIn(variable, os.environ) # Test that reset_environment() works properly. environment.set_value(variable, 1) environment.reset_environment() self.assertNotIn(variable, os.environ)
def task_loop(): """Executes tasks indefinitely.""" # Defer heavy task imports to prevent issues with multiprocessing.Process from bot.tasks import commands clean_exit = False while True: stacktrace = '' exception_occurred = False task = None # This caches the current environment on first run. Don't move this. environment.reset_environment() try: # Run regular updates. update_task.run() update_task.track_revision() task = tasks.get_task() if not task: continue with _Monitor(task): with task.lease(): # Execute the command and delete the task. commands.process_command(task) except SystemExit as e: exception_occurred = True clean_exit = (e.code == 0) if not clean_exit and not isinstance(e, untrusted.HostException): logs.log_error('SystemExit occurred while working on task.') stacktrace = traceback.format_exc() except commands.AlreadyRunningError: exception_occurred = False except Exception: logs.log_error('Error occurred while working on task.') exception_occurred = True stacktrace = traceback.format_exc() if exception_occurred: # Prevent looping too quickly. See: crbug.com/644830 failure_wait_interval = environment.get_value('FAIL_WAIT') time.sleep(utils.random_number(1, failure_wait_interval)) break task_payload = task.payload() if task else None return stacktrace, clean_exit, task_payload
def ResetEnvironment(self, _, context): # pylint: disable=unused-argument environment.reset_environment() return untrusted_runner_pb2.ResetEnvironmentResponse()
def setUp(self): test_helpers.patch_environ(self) environment.reset_environment()