def testIdentifyCulpritForTestTryJobSuccess(self, mock_fn, mock_fn2):
        master_name = 'm'
        builder_name = 'b'
        build_number = 1

        repo_name = 'chromium'
        revision = 'rev2'

        culprit = WfSuspectedCL.Create(repo_name, revision, 100)
        culprit.put()

        culprits_result = {
            'rev1': {
                'revision': 'rev1',
                'repo_name': 'chromium',
                'commit_position': 1,
                'url': 'url_1'
            },
            'rev2': {
                'revision': revision,
                'commit_position': 2,
                'url': 'url_2',
                'repo_name': repo_name
            }
        }

        culprit_map = {'step': {'test1': 'rev1', 'test2': 'rev2'}}
        mock_fn.return_value = culprits_result, ListOfBasestring.FromSerializable(
            []), FailureToCulpritMap.FromSerializable(culprit_map)

        culprits = DictOfBasestring()
        culprits['rev2'] = culprit.key.urlsafe()
        mock_fn2.return_value = culprits

        self.MockGeneratorPipeline(
            pipeline_class=RevertAndNotifyTestCulpritPipeline,
            expected_input=CulpritActionParameters(
                build_key=BuildKey(master_name=master_name,
                                   builder_name=builder_name,
                                   build_number=build_number),
                culprits=culprits,
                heuristic_cls=ListOfBasestring(),
                failure_to_culprit_map=FailureToCulpritMap.FromSerializable(
                    culprit_map)),
            mocked_output=False)

        parameters = IdentifyTestTryJobCulpritParameters(
            build_key=BuildKey(master_name=master_name,
                               builder_name=builder_name,
                               build_number=build_number),
            result=TestTryJobResult.FromSerializable({}))
        pipeline = IdentifyTestTryJobCulpritPipeline(parameters)
        pipeline.start()
        self.execute_queued_tasks()
        mock_fn.assert_called_once_with(parameters)
    def testSendNotificationLatestBuildPassed(self, mocked_pipeline, _):
        master_name = 'm'
        builder_name = 'b'
        build_number = 124

        cl_key = 'mockurlsafekey'
        culprits = DictOfBasestring()
        culprits['r1'] = cl_key
        heuristic_cls = ListOfBasestring()
        heuristic_cls.append(cl_key)
        failure_to_culprit_map = FailureToCulpritMap.FromSerializable(
            {'step1': {
                't1': 'r1'
            }})

        pipeline = RevertAndNotifyTestCulpritPipeline(
            CulpritActionParameters(
                build_key=BuildKey(master_name=master_name,
                                   builder_name=builder_name,
                                   build_number=build_number),
                culprits=culprits,
                heuristic_cls=heuristic_cls,
                failure_to_culprit_map=failure_to_culprit_map))
        pipeline.start(queue_name=constants.DEFAULT_QUEUE)
        self.execute_queued_tasks()
        self.assertFalse(mocked_pipeline.called)
    def testSendNotificationForTestCulpritNoRevert(self, *_):
        master_name = 'm'
        builder_name = 'b'
        build_number = 124

        cl_key = 'mockurlsafekey'
        culprits = DictOfBasestring()
        culprits['r1'] = cl_key
        heuristic_cls = ListOfBasestring()
        heuristic_cls.append(cl_key)

        failure_to_culprit_map = FailureToCulpritMap.FromSerializable(
            {'step1': {
                't1': 'r1'
            }})

        input_object = SendNotificationForCulpritParameters(
            cl_key=cl_key,
            force_notify=True,
            revert_status=services_constants.SKIPPED,
            failure_type=failure_type.TEST)
        self.MockSynchronousPipeline(SendNotificationForCulpritPipeline,
                                     input_object, True)

        pipeline = RevertAndNotifyTestCulpritPipeline(
            CulpritActionParameters(
                build_key=BuildKey(master_name=master_name,
                                   builder_name=builder_name,
                                   build_number=build_number),
                culprits=culprits,
                heuristic_cls=heuristic_cls,
                failure_to_culprit_map=failure_to_culprit_map))
        pipeline.start(queue_name=constants.DEFAULT_QUEUE)
        self.execute_queued_tasks()
Exemplo n.º 4
0
    def testGetCulpritsShouldTakeActions(self, _):
        master_name = 'm'
        builder_name = 'b'
        build_number = 124
        culprits = DictOfBasestring()
        culprits['r1'] = 'mockurlsafekey'
        culprits['r2'] = 'mockurlsafekey2'
        failure_to_culprit_map = FailureToCulpritMap.FromSerializable({
            'step1': {
                'test1': 'r1',
                'test2': 'r2'
            },
            'step2': {
                'test1': 'r2'
            }
        })

        parameters = CulpritActionParameters(
            build_key=BuildKey(master_name=master_name,
                               builder_name=builder_name,
                               build_number=build_number),
            culprits=culprits,
            heuristic_cls=ListOfBasestring(),
            failure_to_culprit_map=failure_to_culprit_map)
        self.assertEqual(
            set(['r1']),
            test_culprit_action.GetCulpritsShouldTakeActions(parameters))
Exemplo n.º 5
0
    def testGetLaterBuildsWithSameTestFailures(self, mock_log, _):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123
        failure_to_culprit_map = FailureToCulpritMap.FromSerializable({
            'a': {
                't1': 'r1',
                't2': 'r1',
                't3': 'r2',
                't4': 'r2'
            },
            'b': {
                't1': 'r3'
            }
        })

        mock_log.side_effect = [{
            't1': 'log',
            't2': 'log',
            't3': 'log'
        }, {
            't1': 'log'
        }, {
            't1': 'log',
            't2': 'log',
        }]

        expected_result = {'a': set(['t1', 't2'])}

        self.assertEqual(
            expected_result,
            ci_test_failure.GetContinuouslyFailedTestsInLaterBuilds(
                master_name, builder_name, build_number,
                failure_to_culprit_map))
Exemplo n.º 6
0
def IdentifyTestTryJobCulprits(parameters):
    """Processes try job result and identifies culprit.

  Args:
    parameters (IdentifyTestTryJobCulpritParameters): Parameters to identify
      culprit from try job result.
  """
    culprits = None
    flaky_failures = {}

    master_name, builder_name, build_number = parameters.build_key.GetParts()
    result = parameters.result
    try_job_id = result.try_job_id if result else None
    failure_to_culprit_map = None
    if try_job_id and result and result.report:
        culprit_map, failed_revisions = FindCulpritForEachTestFailure(result)
        culprits = try_job_service.GetCulpritsWithoutNoBlameAccountsCLS(
            git.GetCommitsInfo(failed_revisions))

        if not culprits:
            flaky_failures = result.report.flakes
        if culprits:
            try_job_data = WfTryJobData.Get(try_job_id)
            UpdateCulpritMapWithCulpritInfo(culprit_map, culprits)
            failure_to_culprit_map = GetCulpritDataForTest(culprit_map)
            try_job_data.culprits = failure_to_culprit_map
            try_job_data.put()
            result.culprit = culprit_map

    # Store try-job results.
    UpdateTryJobResult(parameters, culprits)

    # Saves cls found by heuristic approach for later use.
    # This part must be before UpdateWfAnalysisWithTryJobResult().
    heuristic_cls = build_failure_analysis.GetHeuristicSuspectedCLs(
        master_name, builder_name, build_number)

    # Add try-job results to WfAnalysis.
    UpdateWfAnalysisWithTryJobResult(master_name, builder_name, build_number,
                                     result, culprits, flaky_failures)

    # TODO (chanli): Update suspected_cl for builds in the same group with
    # current build.
    # Updates suspected_cl.
    UpdateSuspectedCLs(master_name, builder_name, build_number, culprits,
                       result)

    return culprits, heuristic_cls, FailureToCulpritMap.FromSerializable(
        failure_to_culprit_map)
    def testSendNotificationToConfirmRevert(self, *_):
        master_name = 'm'
        builder_name = 'b'
        build_number = 124
        build_key = 'm/b/124'

        cl_key = 'mockurlsafekey'
        culprits = DictOfBasestring()
        culprits['r1'] = cl_key
        heuristic_cls = ListOfBasestring()
        heuristic_cls.append(cl_key)
        failure_to_culprit_map = FailureToCulpritMap.FromSerializable(
            {'step1': {
                't1': 'r1'
            }})

        self.MockSynchronousPipeline(
            CreateRevertCLPipeline,
            CreateRevertCLParameters(cl_key=cl_key,
                                     build_key=build_key,
                                     failure_type=failure_type.TEST),
            services_constants.CREATED_BY_FINDIT)
        self.MockSynchronousPipeline(
            SubmitRevertCLPipeline,
            SubmitRevertCLParameters(
                cl_key=cl_key,
                revert_status=services_constants.CREATED_BY_FINDIT,
                failure_type=failure_type.TEST), services_constants.COMMITTED)
        self.MockSynchronousPipeline(
            SendNotificationForCulpritPipeline,
            SendNotificationForCulpritParameters(
                cl_key=cl_key,
                force_notify=True,
                revert_status=services_constants.CREATED_BY_FINDIT,
                failure_type=failure_type.TEST), True)

        pipeline = RevertAndNotifyTestCulpritPipeline(
            CulpritActionParameters(
                build_key=BuildKey(master_name=master_name,
                                   builder_name=builder_name,
                                   build_number=build_number),
                culprits=culprits,
                heuristic_cls=heuristic_cls,
                failure_to_culprit_map=failure_to_culprit_map))
        pipeline.start(queue_name=constants.DEFAULT_QUEUE)
        self.execute_queued_tasks()
Exemplo n.º 8
0
    def testGetLaterBuildsWithSameTestFailuresAllStepsPass(self, _):
        master_name = 'm'
        builder_name = 'b'
        build_number = 123
        failure_to_culprit_map = FailureToCulpritMap.FromSerializable({
            'a': {
                't1': 'r1',
                't2': 'r1',
                't3': 'r2',
                't4': 'r2'
            },
            'b': {
                't1': 'r3'
            }
        })

        self.assertEqual(
            {},
            ci_test_failure.GetContinuouslyFailedTestsInLaterBuilds(
                master_name, builder_name, build_number,
                failure_to_culprit_map))