Example #1
0
    def testOnSwarmingTaskStateChangedCompleted(self, mocked_parse,
                                                mocked_result):
        task_id = 'task_id'
        task_data = {
            'state': constants.STATE_COMPLETED,
        }
        mocked_result.return_value = task_data, None, None

        commit_position = 1000
        isolate_sha = 'sha1'
        iterations = 50
        timeout_seconds = 1200

        parameters = RunFlakeSwarmingTaskInput(builder_name='b',
                                               commit_position=commit_position,
                                               isolate_sha=isolate_sha,
                                               iterations=iterations,
                                               master_name='m',
                                               reference_build_number=123,
                                               step_name='s',
                                               test_name='t',
                                               timeout_seconds=timeout_seconds)

        flake_swarming.OnSwarmingTaskStateChanged(parameters, task_id)
        mocked_parse.assert_called_once_with(task_data, None, None, parameters)
Example #2
0
    def testParseFlakeSwarmingTaskOutputNoOutput(self):
        task_data = {
            'created_ts': '2018-04-02T18:32:06.538220',
            'started_ts': '2018-04-02T19:32:06.538220',
            'completed_ts': '2018-04-02T20:32:06.538220',
            'task_id': 'task_id'
        }
        error = SwarmingTaskError(code=1, message='m')

        commit_position = 1000
        isolate_sha = 'sha1'
        iterations = 50
        timeout_seconds = 1200
        parameters = RunFlakeSwarmingTaskInput(builder_name='b',
                                               commit_position=commit_position,
                                               isolate_sha=isolate_sha,
                                               iterations=iterations,
                                               master_name='m',
                                               reference_build_number=123,
                                               step_name='s',
                                               test_name='t',
                                               timeout_seconds=timeout_seconds)

        expected_result = FlakeSwarmingTaskOutput(
            task_id='task_id',
            started_time=datetime(2018, 4, 2, 19, 32, 6, 538220),
            completed_time=datetime(2018, 4, 2, 20, 32, 6, 538220),
            iterations=None,
            error=error,
            pass_count=None)

        self.assertEqual(
            expected_result,
            flake_swarming._ParseFlakeSwarmingTaskOutput(
                task_data, None, error, parameters))
  def testOnTimeout(self, mock_fn):
    master_name = 'm'
    builder_name = 'b'
    build_number = 123
    step_name = 's'
    test_name = 't'
    commit_position = 1000
    isolate_sha = 'sha1'
    iterations = 50
    timeout_seconds = 1200
    task_id = 'task_id'

    run_flake_swarming_task_input = RunFlakeSwarmingTaskInput(
        builder_name=builder_name,
        commit_position=commit_position,
        isolate_sha=isolate_sha,
        iterations=iterations,
        master_name=master_name,
        reference_build_number=build_number,
        step_name=step_name,
        test_name=test_name,
        timeout_seconds=timeout_seconds)

    pipeline_job = RunFlakeSwarmingTaskPipeline(run_flake_swarming_task_input)
    pipeline_job.OnTimeout(run_flake_swarming_task_input, {'task_id': task_id})
    mock_fn.assert_called_once_with(run_flake_swarming_task_input, task_id)
Example #4
0
    def testOnSwarmingTaskTimeout(self, mocked_parse, mocked_result):
        error = SwarmingTaskError.GenerateError(
            swarming_task_error.RUNNER_TIMEOUT)
        task_id = 'task_id'

        task_data = {
            'state': 'COMPLETE',
        }
        mocked_result.return_value = task_data, 'content', None

        commit_position = 1000
        isolate_sha = 'sha1'
        iterations = 50
        timeout_seconds = 1200

        parameters = RunFlakeSwarmingTaskInput(builder_name='b',
                                               commit_position=commit_position,
                                               isolate_sha=isolate_sha,
                                               iterations=iterations,
                                               master_name='m',
                                               reference_build_number=123,
                                               step_name='s',
                                               test_name='t',
                                               timeout_seconds=timeout_seconds)

        flake_swarming.OnSwarmingTaskTimeout(parameters, task_id)
        mocked_parse.assert_called_once_with(task_data, 'content', error,
                                             parameters)
  def testRunImplNotTriggerSameTaskTwice(self, mock_trigger, _):
    master_name = 'm'
    builder_name = 'b'
    build_number = 123
    step_name = 's'
    test_name = 't'
    commit_position = 1000
    isolate_sha = 'sha1'
    iterations = 50
    timeout_seconds = 1200

    run_flake_swarming_task_input = RunFlakeSwarmingTaskInput(
        builder_name=builder_name,
        commit_position=commit_position,
        isolate_sha=isolate_sha,
        iterations=iterations,
        master_name=master_name,
        reference_build_number=build_number,
        step_name=step_name,
        test_name=test_name,
        timeout_seconds=timeout_seconds)

    pipeline_job = RunFlakeSwarmingTaskPipeline(run_flake_swarming_task_input)
    pipeline_job.RunImpl(run_flake_swarming_task_input)
    self.assertFalse(mock_trigger.called)
  def testCallbackImplFailedRun(self, _):
    master_name = 'm'
    builder_name = 'b'
    build_number = 123
    step_name = 's'
    test_name = 't'
    commit_position = 1000
    isolate_sha = 'sha1'
    iterations = 50
    timeout_seconds = 1200

    run_flake_swarming_task_input = RunFlakeSwarmingTaskInput(
        builder_name=builder_name,
        commit_position=commit_position,
        isolate_sha=isolate_sha,
        iterations=iterations,
        master_name=master_name,
        reference_build_number=build_number,
        step_name=step_name,
        test_name=test_name,
        timeout_seconds=timeout_seconds)

    pipeline_job = RunFlakeSwarmingTaskPipeline(run_flake_swarming_task_input)
    result = pipeline_job.CallbackImpl(run_flake_swarming_task_input,
                                       {'task_id': 'task_id'})
    self.assertEqual(('Error getting swarming task result: m', None), result)
 def testCallbackImplNoTaskID(self, mocked_pipeline_id, mock_fn):
   mocked_pipeline_id.__get__ = mock.Mock(return_value='pipeline-id')
   pipeline_input = RunFlakeSwarmingTaskInput.FromSerializable({})
   p = RunFlakeSwarmingTaskPipeline(pipeline_input)
   result = p.CallbackImpl(pipeline_input, {})
   self.assertEqual(('Task_id not found for pipeline pipeline-id', None),
                    result)
   self.assertFalse(mock_fn.called)
  def testParseFlakeSwarmingTaskOutput(self, mocked_pass_fail):
    iterations = 50
    pass_count = 25
    task_data = {
        'created_ts': '2018-04-02T18:32:06.538220',
        'started_ts': '2018-04-02T19:32:06.538220',
        'completed_ts': '2018-04-02T20:32:06.538220',
        'task_id': 'task_id'
    }

    mocked_pass_fail.return_value = (iterations, pass_count)

    commit_position = 1000
    isolate_sha = 'sha1'
    iterations = 50
    timeout_seconds = 1200

    parameters = RunFlakeSwarmingTaskInput(
        builder_name='b',
        commit_position=commit_position,
        isolate_sha=isolate_sha,
        iterations=iterations,
        master_name='m',
        reference_build_number=123,
        step_name='s',
        test_name='t',
        timeout_seconds=timeout_seconds)

    expected_result = FlakeSwarmingTaskOutput(
        task_id='task_id',
        started_time=datetime(2018, 4, 2, 19, 32, 6, 538220),
        completed_time=datetime(2018, 4, 2, 20, 32, 6, 538220),
        iterations=iterations,
        error=None,
        pass_count=pass_count)

    self.assertEqual(
        expected_result,
        flake_swarming._ParseFlakeSwarmingTaskOutput(task_data, 'content', None,
                                                     parameters))
  def testRunImplTriggerTaskFailed(self, mocked_pipeline_id, mock_trigger, _):
    master_name = 'm'
    builder_name = 'b'
    build_number = 123
    step_name = 's'
    test_name = 't'
    commit_position = 1000
    isolate_sha = 'sha1'
    iterations = 50
    timeout_seconds = 1200
    pipeline_id = 'pipeline-id'

    run_flake_swarming_task_input = RunFlakeSwarmingTaskInput(
        builder_name=builder_name,
        commit_position=commit_position,
        isolate_sha=isolate_sha,
        iterations=iterations,
        master_name=master_name,
        reference_build_number=build_number,
        step_name=step_name,
        test_name=test_name,
        timeout_seconds=timeout_seconds)

    mock_trigger.return_value = None

    mocked_pipeline_id.__get__ = mock.Mock(return_value=pipeline_id)
    pipeline_job = RunFlakeSwarmingTaskPipeline(run_flake_swarming_task_input)
    with self.assertRaises(pipeline.Retry):
      pipeline_job.RunImpl(run_flake_swarming_task_input)

    mock_trigger.assert_called_once_with(
        master_name=master_name,
        builder_name=builder_name,
        reference_build_number=build_number,
        step_name=step_name,
        test_name=test_name,
        isolate_sha=isolate_sha,
        iterations=iterations,
        timeout_seconds=timeout_seconds,
        runner_id=pipeline_id)
Example #10
0
    def testOnSwarmingTaskStateChangedRunning(self, mocked_result):
        task_id = 'task_id'
        task_data = {'state': constants.STATE_RUNNING}
        mocked_result.return_value = task_data, None, None

        commit_position = 1000
        isolate_sha = 'sha1'
        iterations = 50
        timeout_seconds = 1200

        parameters = RunFlakeSwarmingTaskInput(builder_name='b',
                                               commit_position=commit_position,
                                               isolate_sha=isolate_sha,
                                               iterations=iterations,
                                               master_name='m',
                                               reference_build_number=123,
                                               step_name='s',
                                               test_name='t',
                                               timeout_seconds=timeout_seconds)

        self.assertIsNone(
            flake_swarming.OnSwarmingTaskStateChanged(parameters, task_id))
Example #11
0
    def testOnSwarmingTaskStateChangedNoTaskData(self, mocked_error,
                                                 mocked_result):

        commit_position = 1000
        isolate_sha = 'sha1'
        iterations = 50
        timeout_seconds = 1200

        parameters = RunFlakeSwarmingTaskInput(builder_name='b',
                                               commit_position=commit_position,
                                               isolate_sha=isolate_sha,
                                               iterations=iterations,
                                               master_name='m',
                                               reference_build_number=123,
                                               step_name='s',
                                               test_name='t',
                                               timeout_seconds=timeout_seconds)

        task_id = 'task_id'
        mocked_result.return_value = None, None, None

        flake_swarming.OnSwarmingTaskStateChanged(parameters, task_id)
        mocked_error.assert_called_once_with(task_id, None)
Example #12
0
    def testParseFlakeSwarmingTaskOutputConsolidatedResult(self, _):
        task_data = {
            'created_ts': '2018-04-02T18:32:06.538220',
            'started_ts': '2018-04-02T19:32:06.538220',
            'task_id': 'task_id',
            'state': 'COMPLETED',
            'failure': False,
            'internal_failure': False
        }

        commit_position = 1000
        isolate_sha = 'sha1'
        iterations = 50
        timeout_seconds = 1200
        parameters = RunFlakeSwarmingTaskInput(builder_name='b',
                                               commit_position=commit_position,
                                               isolate_sha=isolate_sha,
                                               iterations=iterations,
                                               master_name='m',
                                               reference_build_number=123,
                                               step_name='s',
                                               test_name='t',
                                               timeout_seconds=timeout_seconds)

        expected_result = FlakeSwarmingTaskOutput(task_id='task_id',
                                                  started_time=datetime(
                                                      2018, 4, 2, 19, 32, 6,
                                                      538220),
                                                  completed_time=None,
                                                  iterations=50,
                                                  error=None,
                                                  pass_count=0)

        self.assertEqual(
            expected_result,
            flake_swarming._ParseFlakeSwarmingTaskOutput(
                task_data, {'bla': 'bla'}, None, parameters))
  def testTimeoutSeconds(self):
    master_name = 'm'
    builder_name = 'b'
    build_number = 123
    step_name = 's'
    test_name = 't'
    commit_position = 1000
    isolate_sha = 'sha1'
    iterations = 50
    timeout_seconds = 1200

    run_flake_swarming_task_input = RunFlakeSwarmingTaskInput(
        builder_name=builder_name,
        commit_position=commit_position,
        isolate_sha=isolate_sha,
        iterations=iterations,
        master_name=master_name,
        reference_build_number=build_number,
        step_name=step_name,
        test_name=test_name,
        timeout_seconds=timeout_seconds)

    pipeline_job = RunFlakeSwarmingTaskPipeline(run_flake_swarming_task_input)
    self.assertEqual(24 * 60 * 60, pipeline_job.TimeoutSeconds())
  def testCallbackImplCompleted(self, mocked_output):
    master_name = 'm'
    builder_name = 'b'
    build_number = 123
    step_name = 's'
    test_name = 't'
    commit_position = 1000
    isolate_sha = 'sha1'
    iterations = 50
    timeout_seconds = 1200

    run_flake_swarming_task_input = RunFlakeSwarmingTaskInput(
        builder_name=builder_name,
        commit_position=commit_position,
        isolate_sha=isolate_sha,
        iterations=iterations,
        master_name=master_name,
        reference_build_number=build_number,
        step_name=step_name,
        test_name=test_name,
        timeout_seconds=timeout_seconds)

    flake_swarming_task_output = FlakeSwarmingTaskOutput(
        completed_time=datetime(2018, 4, 1, 0, 1, 0),
        error=None,
        iterations=iterations,
        pass_count=iterations,
        started_time=datetime(2018, 4, 1, 0, 0, 0),
        task_id='task_id')

    mocked_output.return_value = flake_swarming_task_output

    pipeline_job = RunFlakeSwarmingTaskPipeline(run_flake_swarming_task_input)
    result = pipeline_job.CallbackImpl(run_flake_swarming_task_input,
                                       {'task_id': 'task_id'})
    self.assertEqual((None, flake_swarming_task_output), result)
Example #15
0
  def testDetermineApproximatePassRateNotYetConverged(self, *_):
    master_name = 'm'
    builder_name = 'b'
    reference_build_number = 123
    step_name = 's'
    test_name = 't'
    commit_position = 1000
    incoming_pass_count = 15
    iterations_completed = 30
    expected_iterations = 15
    incoming_pass_rate = 0.5
    isolate_sha = 'sha1'
    revision = 'r1000'
    timeout_seconds = 3600
    started_time = datetime(2018, 1, 1, 0, 0, 0)
    completed_time = datetime(2018, 1, 1, 1, 0, 0)
    build_url = None
    try_job_url = 'url'

    isolate_sha_output = GetIsolateShaOutput(
        build_number=None,
        build_url=build_url,
        isolate_sha=isolate_sha,
        try_job_url=try_job_url)

    flakiness_thus_far = Flakiness(
        build_number=None,
        build_url=build_url,
        commit_position=commit_position,
        total_test_run_seconds=timeout_seconds,
        error=None,
        failed_swarming_task_attempts=0,
        iterations=iterations_completed,
        pass_rate=incoming_pass_rate,
        revision=revision,
        try_job_url=try_job_url,
        task_ids=ListOfBasestring.FromSerializable(['task_id_1']))

    incoming_flake_swarming_task_output = FlakeSwarmingTaskOutput(
        error=None,
        pass_count=incoming_pass_count,
        iterations=iterations_completed,
        started_time=started_time,
        completed_time=completed_time,
        task_id='task_id_2')

    expected_aggregate_flakiness_input = AggregateFlakinessInput(
        flakiness_thus_far=flakiness_thus_far,
        incoming_swarming_task_output=incoming_flake_swarming_task_output)

    expected_aggregate_flakiness_output = Flakiness(
        build_number=None,
        build_url=build_url,
        commit_position=commit_position,
        total_test_run_seconds=timeout_seconds,
        error=None,
        failed_swarming_task_attempts=0,
        iterations=45,
        pass_rate=0.5,
        revision=revision,
        try_job_url=try_job_url,
        task_ids=ListOfBasestring.FromSerializable(['task_id_1']))

    determine_approximate_pass_rate_input = DetermineApproximatePassRateInput(
        builder_name=builder_name,
        commit_position=commit_position,
        flakiness_thus_far=flakiness_thus_far,
        get_isolate_sha_output=isolate_sha_output,
        master_name=master_name,
        previous_swarming_task_output=incoming_flake_swarming_task_output,
        reference_build_number=reference_build_number,
        revision=revision,
        step_name=step_name,
        test_name=test_name)

    flake_swarming_task_input = RunFlakeSwarmingTaskInput(
        builder_name=builder_name,
        commit_position=commit_position,
        isolate_sha=isolate_sha,
        iterations=expected_iterations,
        master_name=master_name,
        reference_build_number=reference_build_number,
        step_name=step_name,
        test_name=test_name,
        timeout_seconds=timeout_seconds)

    recursive_input = DetermineApproximatePassRateInput(
        builder_name=builder_name,
        commit_position=commit_position,
        flakiness_thus_far=expected_aggregate_flakiness_output,
        get_isolate_sha_output=isolate_sha_output,
        master_name=master_name,
        previous_swarming_task_output=incoming_flake_swarming_task_output,
        reference_build_number=reference_build_number,
        revision=revision,
        step_name=step_name,
        test_name=test_name)

    self.MockAsynchronousPipeline(RunFlakeSwarmingTaskPipeline,
                                  flake_swarming_task_input,
                                  incoming_flake_swarming_task_output)
    self.MockSynchronousPipeline(AggregateFlakinessPipeline,
                                 expected_aggregate_flakiness_input,
                                 expected_aggregate_flakiness_output)
    self.MockGeneratorPipeline(DetermineApproximatePassRatePipelineWrapper,
                               recursive_input, None)

    pipeline_job = DetermineApproximatePassRatePipeline(
        determine_approximate_pass_rate_input)
    pipeline_job.start()
    self.execute_queued_tasks()