示例#1
0
    def test_command_override(self):
        """Test command override."""
        environment.set_value('COMMAND_OVERRIDE', 'test override job')
        tasks.add_task('test', 'normal', 'job', wait_time=0)

        task = tasks.get_task()
        self.assertEqual('test', task.command)
        self.assertEqual('override', task.argument)
        self.assertEqual('job', task.job)
        self.assertEqual('test override job', task.payload())
示例#2
0
def task_loop():
  """Executes tasks indefinitely."""
  # Defer heavy task imports to prevent issues with multiprocessing.Process
  from clusterfuzz._internal.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
示例#3
0
    def test_preemptible(self):
        """Test preemptible bot tasks."""
        environment.set_value('PREEMPTIBLE', True)
        environment.set_value('THREAD_MULTIPLIER', 1)
        tasks.add_task('test',
                       'high',
                       'job',
                       queue='high-end-jobs-linux',
                       wait_time=0)
        tasks.add_task('test',
                       'normal',
                       'job',
                       queue='jobs-linux',
                       wait_time=0)

        task = tasks.get_task()
        self.assertIsNone(task)
示例#4
0
    def test_regular(self):
        """Test regular tasks."""
        environment.set_value('THREAD_MULTIPLIER', 1)
        tasks.add_task('test',
                       'high',
                       'job',
                       queue='high-end-jobs-linux',
                       wait_time=0)
        tasks.add_task('test',
                       'normal',
                       'job',
                       queue='jobs-linux',
                       wait_time=0)

        task = tasks.get_task()
        self.assertEqual('test', task.command)
        self.assertEqual('normal', task.argument)
        self.assertEqual('job', task.job)
        self.assertEqual('test normal job', task.payload())
示例#5
0
    def test_defer(self):
        """Test deferring tasks which shouldn't be run yet."""
        tasks.add_task('test', 'normal1', 'job', wait_time=60)
        tasks.add_task('test', 'normal2', 'job', wait_time=600)
        tasks.add_task('test', 'normal3', 'job', wait_time=700)
        tasks.add_task('test', 'normal4', 'job', wait_time=0)

        with mock.patch.object(pubsub.ReceivedMessage,
                               'modify_ack_deadline') as mock_modify:
            task = tasks.get_task()
            self.assertEqual('test', task.command)
            self.assertEqual('normal4', task.argument)
            self.assertEqual('job', task.job)
            self.assertEqual('test normal4 job', task.payload())

            self.assertEqual(3, mock_modify.call_count)
            mock_modify.assert_has_calls([
                mock.call(60),
                mock.call(600),
                mock.call(600),
            ])