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()
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 testCanAutoCreateRevert(self, _): repo_name = 'chromium' revision = 'rev1' culprit = WfSuspectedCL.Create(repo_name, revision, 123) culprit.failure_type.append(failure_type.TEST) culprit.revert_created_time = datetime(2018, 2, 14, 12, 0, 0) culprit.put() culprit_dict = DictOfBasestring() culprit_dict[revision] = culprit.key.urlsafe() heuristic_cls = ListOfBasestring() heuristic_cls.append(culprit.key.urlsafe()) parameters_dict = { 'build_key': { 'master_name': 'm', 'builder_name': 'b', 'build_number': 123 }, 'culprits': { 'rev1': culprit.key.urlsafe() }, 'heuristic_cls': heuristic_cls } parameters = CulpritActionParameters.FromSerializable(parameters_dict) self.assertTrue( test_culprit_action.CanAutoCreateRevert(culprit.key.urlsafe(), parameters))
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))
def setUp(self): super(TestCulpritActionTest, self).setUp() repo_name = 'chromium' revision = 'rev1' self.culprit = WfSuspectedCL.Create(repo_name, revision, 100).put().urlsafe() culprit_dict = DictOfBasestring() culprit_dict[revision] = self.culprit heuristic_cls = ListOfBasestring() heuristic_cls.append(self.culprit) parameters_dict = { 'build_key': { 'master_name': 'm', 'builder_name': 'b', 'build_number': 123 }, 'culprits': { 'rev1': self.culprit }, 'heuristic_cls': heuristic_cls } self.parameters = CulpritActionParameters.FromSerializable( parameters_dict)
def testReturnNoneIfNoTryJob(self): master_name = 'm' builder_name = 'b' build_number = 8 WfTryJob.Create(master_name, builder_name, build_number).put() self.MockGeneratorPipeline( pipeline_class=RevertAndNotifyTestCulpritPipeline, expected_input=CulpritActionParameters( build_key=BuildKey(master_name=master_name, builder_name=builder_name, build_number=build_number), culprits=DictOfBasestring(), heuristic_cls=ListOfBasestring(), failure_to_culprit_map=None), mocked_output=False) parameters = IdentifyTestTryJobCulpritParameters(build_key=BuildKey( master_name=master_name, builder_name=builder_name, build_number=build_number), result=None) pipeline = IdentifyTestTryJobCulpritPipeline(parameters) pipeline.start() self.execute_queued_tasks() try_job = WfTryJob.Get(master_name, builder_name, build_number) self.assertEqual(try_job.test_results, []) self.assertEqual(try_job.status, analysis_status.COMPLETED)
def testIdentifyCulpritForCompileTryJobSuccess(self, mock_fn): master_name = 'm' builder_name = 'b' build_number = 1 try_job_id = '1' compile_result = { 'report': { 'result': { 'rev1': 'passed', 'rev2': 'failed' }, 'culprit': 'rev2' }, 'try_job_id': try_job_id, } repo_name = 'chromium' revision = 'rev2' culprit = WfSuspectedCL.Create(repo_name, revision, 100) culprit.put() culprits_result = { 'rev2': { 'revision': revision, 'commit_position': 2, 'url': 'url_2', 'repo_name': repo_name } } mock_fn.return_value = culprits_result, ListOfBasestring() culprits = DictOfBasestring() culprits['rev2'] = culprit.key.urlsafe() self.MockGeneratorPipeline(pipeline_class=revert_pipeline. RevertAndNotifyCompileCulpritPipeline, 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=None), mocked_output=False) pipeline_input = IdentifyCompileTryJobCulpritParameters( build_key=BuildKey(master_name=master_name, builder_name=builder_name, build_number=build_number), result=CompileTryJobResult.FromSerializable(compile_result)) pipeline = culprit_pipeline.IdentifyCompileTryJobCulpritPipeline( pipeline_input) pipeline.start() self.execute_queued_tasks()
def GetWfSuspectedClKeysFromCLInfo(cl_info): """Get a dict of urlsafe keys object from result of GetCLInfo.""" cl_keys = DictOfBasestring() for revision, info in cl_info.iteritems(): culprit = WfSuspectedCL.Get(info['repo_name'], info['revision']) if not culprit: continue cl_keys[revision] = culprit.key.urlsafe() return cl_keys
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 testShouldTakeActionsOnCulprit(self, _): master_name = 'm' builder_name = 'b' build_number = 124 culprits = DictOfBasestring() culprits['r1'] = 'mockurlsafekey' parameters = CulpritActionParameters(build_key=BuildKey( master_name=master_name, builder_name=builder_name, build_number=build_number), culprits=culprits, heuristic_cls=ListOfBasestring()) self.assertTrue( compile_culprit_action.ShouldTakeActionsOnCulprit(parameters))
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) self.MockSynchronousPipeline( CreateRevertCLPipeline, CreateRevertCLParameters(cl_key=cl_key, build_key=build_key, failure_type=failure_type.COMPILE), services_constants.CREATED_BY_FINDIT) self.MockSynchronousPipeline( SubmitRevertCLPipeline, SubmitRevertCLParameters( cl_key=cl_key, revert_status=services_constants.CREATED_BY_FINDIT, failure_type=failure_type.COMPILE), services_constants.COMMITTED) self.MockSynchronousPipeline( SendNotificationToIrcPipeline, SendNotificationToIrcParameters( cl_key=cl_key, revert_status=services_constants.CREATED_BY_FINDIT, commit_status=services_constants.COMMITTED, failure_type=failure_type.COMPILE), True) self.MockSynchronousPipeline( SendNotificationForCulpritPipeline, SendNotificationForCulpritParameters( cl_key=cl_key, force_notify=True, revert_status=services_constants.CREATED_BY_FINDIT, failure_type=failure_type.COMPILE), True) pipeline = wrapper_pipeline.RevertAndNotifyCompileCulpritPipeline( 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=None)) pipeline.start(queue_name=constants.DEFAULT_QUEUE) self.execute_queued_tasks()
def testCreatedRevertButNotCommitted(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( 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()
def testShouldForceNotify(self): cl_key = 'mockurlsafekey' culprit_dict = DictOfBasestring() culprit_dict['rev1'] = cl_key heuristic_cls = ListOfBasestring() heuristic_cls.append(cl_key) parameters_dict = { 'build_key': { 'master_name': 'm', 'builder_name': 'b', 'build_number': 123 }, 'culprits': { 'rev1': culprit_dict }, 'heuristic_cls': heuristic_cls } self.assertTrue( culprit_action.ShouldForceNotify( cl_key, CulpritActionParameters.FromSerializable(parameters_dict)))