def testMergeOrSplitFlakeIssueByCulpritIssueAlreadyMerged( self, mocked_get_issue, mocked_merge_issues, _): # Culprit's flake issue 12344 was already merged into 12346. # Incoming flake issue's id is 12345 and is expected to be merged as well. project = 'chromium' merged_bug_id = 12344 open_bug_id = 12345 destination_bug_id = 12346 revision = 'r1000' commit_position = 1000 flake_issue = FlakeIssue.Create(project, open_bug_id) flake_issue.put() destination_issue = FlakeIssue.Create(project, destination_bug_id) destination_issue.put() culprit_flake_issue = FlakeIssue.Create(project, merged_bug_id) culprit_flake_issue.status = 'Merged' culprit_flake_issue.merge_destination_key = destination_issue.key culprit_flake_issue.put() flake_culprit = FlakeCulprit.Create(project, revision, commit_position) flake_culprit.flake_issue_key = culprit_flake_issue.key flake_culprit.put() flake_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(open_bug_id) }) destination_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(destination_bug_id) }) mocked_get_issue.side_effect = [ destination_monorail_issue, flake_monorail_issue, ] (duplicate, destination) = flake_analysis_actions.MergeOrSplitFlakeIssueByCulprit( flake_issue.key, flake_culprit.key) mocked_merge_issues.assert_called_once_with( flake_monorail_issue, destination_monorail_issue, mock.ANY) flake_issue = flake_issue.key.get() self.assertEqual(flake_issue.key, duplicate) self.assertEqual(destination_issue.key, destination) self.assertEqual(destination_issue.key, flake_issue.merge_destination_key)
def testMergeOrSplitFlakeIssueByCulpritMergeIntoManuallyCreated( self, mocked_get_issue, mocked_merge_issues, _): project = 'chromium' duplicate_bug_id = 12344 manually_created_bug_id = 12345 revision = 'r1000' commit_position = 1000 flake_issue = FlakeIssue.Create(project, manually_created_bug_id) flake_issue.status = 'Assigned' flake_issue.put() culprit_flake_issue = FlakeIssue.Create(project, duplicate_bug_id) culprit_flake_issue.put() flake_culprit = FlakeCulprit.Create(project, revision, commit_position) flake_culprit.flake_issue_key = culprit_flake_issue.key flake_culprit.put() # Even though the flake issue associated with the culprit was identified # first, the incoming flake issue was manually created. Merge into the # manually created one. flake_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(manually_created_bug_id) }) culprit_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(duplicate_bug_id) }) mocked_get_issue.side_effect = [ culprit_monorail_issue, flake_monorail_issue ] (duplicate, destination) = flake_analysis_actions.MergeOrSplitFlakeIssueByCulprit( flake_issue.key, flake_culprit.key) mocked_merge_issues.assert_called_once_with(culprit_monorail_issue, flake_monorail_issue, mock.ANY) flake_culprit = flake_culprit.key.get() flake_issue = flake_issue.key.get() culprit_flake_issue = culprit_flake_issue.key.get() self.assertEqual(culprit_flake_issue.key, duplicate) self.assertEqual(flake_issue.key, destination) self.assertEqual(flake_issue.flake_culprit_key, flake_culprit.key) self.assertEqual(flake_issue.key, culprit_flake_issue.merge_destination_key)
def testMergeOrSplitFlakeIssueByCulpritIssueClosed(self, mocked_get_issue, mocked_merge_issues, *_): project = 'chromium' closed_bug_id = 12344 open_bug_id = 12345 revision = 'r1000' commit_position = 1000 flake_issue = FlakeIssue.Create(project, open_bug_id) flake_issue.put() culprit_flake_issue = FlakeIssue.Create(project, closed_bug_id) culprit_flake_issue.status = 'Fixed' culprit_flake_issue.last_updated_time_in_monorail = datetime( 2019, 1, 1) culprit_flake_issue.put() flake_culprit = FlakeCulprit.Create(project, revision, commit_position) flake_culprit.flake_issue_key = culprit_flake_issue.key flake_culprit.put() # Even though the flake issue associated with the culprit was identified # first, it has been closed. FlakeCulprit should have its flake issue # updated to the incoming one. flake_monorail_issue = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(open_bug_id) }) culprit_monorail_issue = Issue({ 'status': 'Fixed', 'projectId': 'chromium', 'id': str(closed_bug_id) }) mocked_get_issue.side_effect = [ culprit_monorail_issue, flake_monorail_issue ] (duplicate, destination) = flake_analysis_actions.MergeOrSplitFlakeIssueByCulprit( flake_issue.key, flake_culprit.key) mocked_merge_issues.assert_not_called() flake_culprit = flake_culprit.key.get() self.assertIsNone(duplicate) self.assertIsNone(destination) self.assertIsNone(flake_issue.merge_destination_key) self.assertEqual(flake_issue.key, flake_culprit.flake_issue_key)
def testGetMostUpdatedIssue(self): monorail_project = 'chromium' issue_id = 12345 merge_issue_id = 67890 merge_issue = FlakeIssue.Create(monorail_project=monorail_project, issue_id=merge_issue_id) merge_issue.put() flake_issue = FlakeIssue.Create(monorail_project=monorail_project, issue_id=issue_id) flake_issue.merge_destination_key = merge_issue.key flake_issue.put() self.assertEqual(merge_issue, flake_issue.GetMostUpdatedIssue())
def _GetIssueGenerator(self, new_issue=True): luci_project = 'chromium' normalized_step_name = 'step' flake0 = Flake.Create(luci_project, normalized_step_name, 'suite.test0', 'suite.test0') flake0.tags = ['component::Blink'] flake0.put() flake1 = Flake.Create(luci_project, normalized_step_name, 'suite.test1', 'suite.test1') flake1.tags = ['component::Blink/Infra'] flake1.put() flake2 = Flake.Create(luci_project, normalized_step_name, 'suite.test2', 'suite.test2') flake2.put() flake3 = Flake.Create(luci_project, 'other_step', 'other_test', 'other_test') flake3.put() issue_generator_new = issue_generator.FlakeDetectionGroupIssueGenerator( flakes=[flake0, flake1, flake2], num_occurrences=5, canonical_step_name=normalized_step_name) flake_issue = FlakeIssue.Create(luci_project, 12345) flake_issue.put() issue_generator_old = issue_generator.FlakeDetectionGroupIssueGenerator( flakes=[flake1, flake2, flake3], num_occurrences=5, flake_issue=flake_issue, flakes_with_same_occurrences=False) return issue_generator_new if new_issue else issue_generator_old
def testOnCulpritIdentified(self, mocked_update_monorail, mocked_update_issues, mocked_merge): project = 'chromium' master_name = 'm' builder_name = 'b' build_number = 123 step_name = 's' test_name = 't' label = 'l' bug_id = 12345 merged_bug_id = 12344 revision = 'r1000' commit_position = 1000 merged_issue = FlakeIssue.Create(project, merged_bug_id) merged_issue.put() issue = FlakeIssue.Create(project, bug_id) issue.merge_destination_key = merged_issue.key issue.put() flake = Flake.Create(project, step_name, test_name, label) flake.flake_issue_key = issue.key flake.put() culprit = FlakeCulprit.Create(project, revision, commit_position) culprit.flake_issue_key = merged_issue.key culprit.put() mocked_merge.return_value = (issue.key, merged_issue.key) analysis = MasterFlakeAnalysis.Create(master_name, builder_name, build_number, step_name, test_name) analysis.flake_key = flake.key analysis.culprit_urlsafe_key = culprit.key.urlsafe() analysis.confidence_in_culprit = 0.9 analysis.put() flake_analysis_actions.OnCulpritIdentified(analysis.key.urlsafe()) mocked_merge.assert_called_once_with(issue.key, culprit.key) mocked_update_issues.assert_called_once_with( issue.key, issue.merge_destination_key) mocked_update_monorail.assert_called_once_with(analysis.key.urlsafe())
def testGetMostUpdatedIssueNoMergeKeyOnly(self): monorail_project = 'chromium' issue_id = 12345 flake_issue = FlakeIssue.Create(monorail_project=monorail_project, issue_id=issue_id) flake_issue.put() self.assertEqual(flake_issue.key, flake_issue.GetMostUpdatedIssue(key_only=True))
def _GetOrCreateFlakeIssue(bug_id): monorail_project = 'chromium' issue = FlakeIssue.Get(monorail_project, bug_id) if issue: return issue issue = FlakeIssue.Create(monorail_project, bug_id) if bug_id >= 123458: issue.create_time_in_monorail = datetime(2018, 9, 1) issue.put() return issue
def testGetFlakeIssue(self): flake_issue = FlakeIssue.Create(monorail_project='chromium', issue_id=12345) flake_issue.put() flake_issue_key = flake_issue.key flake = Flake.Create(luci_project='chromium', normalized_step_name='step', normalized_test_name='suite.test', test_label_name='*/suite.test/*') flake.flake_issue_key = flake_issue_key flake.put() self.assertEqual(flake_issue_key, flake.GetIssue(up_to_date=True, key_only=True))
def testGetFlakeIssueDataInconsistent(self): flake_issue = FlakeIssue.Create(monorail_project='chromium', issue_id=12345) flake_issue.put() flake_issue_key = flake_issue.key flake = Flake.Create(luci_project='chromium', normalized_step_name='step', normalized_test_name='suite.test', test_label_name='*/suite.test/*') flake.flake_issue_key = flake_issue_key flake.put() flake_issue_key.delete() self.assertIsNone(flake.GetIssue())
def testMergeOrSplitFlakeIssueByCulpritFlakeIssueClosedLongAgo(self, _): project = 'chromium' duplicate_bug_id = 12344 manually_created_bug_id = 12345 revision = 'r1000' commit_position = 1000 flake_issue = FlakeIssue.Create(project, manually_created_bug_id) flake_issue.status = 'Fixed' flake_issue.last_updated_time_in_monorail = datetime(2019, 1, 1) flake_issue.put() culprit_flake_issue = FlakeIssue.Create(project, duplicate_bug_id) culprit_flake_issue.put() flake_culprit = FlakeCulprit.Create(project, revision, commit_position) flake_culprit.flake_issue_key = culprit_flake_issue.key flake_culprit.put() (duplicate, destination) = flake_analysis_actions.MergeOrSplitFlakeIssueByCulprit( flake_issue.key, flake_culprit.key) self.assertIsNone(duplicate) self.assertIsNone(destination)
def testGetIssue(self): luci_project = 'chromium' normalized_step_name = 'normalized_step' normalized_test_name = 'a/b.html' test_label_name = 'test_label' bug_id = 12345 flake_issue = FlakeIssue.Create(luci_project, bug_id) flake_issue.put() flake = Flake.Create(luci_project=luci_project, normalized_step_name=normalized_step_name, normalized_test_name=normalized_test_name, test_label_name=test_label_name) flake.flake_issue_key = flake_issue.key self.assertEqual(flake_issue, flake.GetIssue())
def testCreate(self): monorail_project = 'chromium' issue_id = 123 FlakeIssue.Create(monorail_project=monorail_project, issue_id=issue_id).put() flake_issue = FlakeIssue.Get(monorail_project, issue_id) fetched_flake_issues = FlakeIssue.query().fetch() self.assertEqual(1, len(fetched_flake_issues)) self.assertEqual(flake_issue, fetched_flake_issues[0]) self.assertIsNone( fetched_flake_issues[0].last_updated_time_by_flake_detection) self.assertEqual(monorail_project, flake_issue.monorail_project) self.assertEqual(issue_id, flake_issue.issue_id) self.assertIsNone(flake_issue.merge_destination_key)
def testGetFirstCommentWhenBugJustCreated(self): issue_generator_new = self._GetIssueGenerator() flake_issue = FlakeIssue.Create('chromium', 12345) flake_issue.put() issue_generator_new.SetFlakeIssue(flake_issue) wrong_result_link = ( 'https://bugs.chromium.org/p/chromium/issues/entry?' 'status=Unconfirmed&labels=Pri-1,Test-Findit-Wrong&' 'components=Infra%3ETest%3EFlakiness&' 'summary=%5BFindit%5D%20Flake%20Detection%20-%20Wrong%20result%3A%20' 'Tests in step&comment=Link%20to%20flake%20details%3A%20' 'https://analysis.chromium.org/p/chromium/flake-portal/flakes?bug_id={}' ).format(flake_issue.issue_id) expected_description = _EXPECTED_GROUP_FIRST_COMMENT.format( flake_issue.issue_id, wrong_result_link) self.assertEqual(expected_description, issue_generator_new.GetFirstCommentWhenBugJustCreated())
def testGenerateDisabledTestsData(self): disabled_test_key = LuciTest.CreateKey('a', 'b', 'c') disabled_tests = [ LuciTest(key=disabled_test_key, disabled_test_variants={('os:Mac1234', ), ('Unknown', )}, last_updated_time=datetime(2019, 6, 29, 0, 0, 0), issue_keys=[ndb.Key('FlakeIssue', 'chromium@123')]) ] flake_issue = FlakeIssue.Create('chromium', 123) flake_issue.put() expected_disabled_test_dictionaries = [{ 'luci_project': 'a', 'normalized_step_name': 'b', 'normalized_test_name': 'c', 'disabled_test_variants': [ [ 'os:Mac', ], [ 'Unknown', ], ], 'issue_keys': [ndb.Key('FlakeIssue', 'chromium@123')], 'issues': [ { 'issue_id': 123, 'issue_link': 'https://monorail-prod.appspot.com/p/chromium/issues/detail?id=123', }, ], 'tags': [], 'disabled': True, 'last_updated_time': datetime(2019, 6, 29, 0, 0, 0), }] self.assertEqual( expected_disabled_test_dictionaries, disabled_test_detection_utils.GenerateDisabledTestsData( disabled_tests))
def testMergeOrSplitFlakeIssueByCulprit(self): project = 'chromium' bug_id = 12345 revision = 'r1000' commit_position = 1000 issue = FlakeIssue.Create(project, bug_id) issue.put() culprit = FlakeCulprit.Create(project, revision, commit_position) culprit.put() flake_analysis_actions.MergeOrSplitFlakeIssueByCulprit( issue.key, culprit.key) issue = issue.key.get() culprit = culprit.key.get() self.assertEqual(culprit.key, issue.flake_culprit_key) self.assertEqual(issue.key, culprit.flake_issue_key)
def _GetOrCreateFlakeIssue(issue_id, monorail_project): """Gets or creates a FlakeIssue entity for the monorail issue. Args: issue_id (int): Id of the issue. monorail_project (str): Monorail project of the issue. Returns: (FlakeIssue): a FlakeIssue entity of the issue. """ flake_issue = FlakeIssue.Get(monorail_project, issue_id) if flake_issue: return flake_issue flake_issue = FlakeIssue.Create(monorail_project, issue_id) flake_issue.put() monorail_issue = monorail_util.GetMonorailIssueForIssueId( issue_id, monorail_project) _UpdateFlakeIssueWithMonorailIssue(flake_issue, monorail_issue) return flake_issue
def testUpdate(self): monorail_project = 'chromium' issue_id = 12345 updated_time = datetime(2018, 12, 4, 0, 0, 0) status = 'Assigned' labels = ['Type-Bug', 'Pri-1'] flake_issue = FlakeIssue.Create(monorail_project=monorail_project, issue_id=issue_id) flake_issue.put() flake_issue.Update(last_updated_time_in_monorail=updated_time, status=status, labels=labels) flake_issue = flake_issue.key.get() self.assertEqual(status, flake_issue.status) self.assertEqual(labels, flake_issue.labels) self.assertEqual(updated_time, flake_issue.last_updated_time_in_monorail)
def testUpdateMonorailBugWithCulprit(self, mock_update, mock_comments, mock_get_issue, *_): project = 'chromium' bug_id = 12345 step_name = 's' test_name = 't' label = 'l' flake_issue = FlakeIssue.Create(project, bug_id) flake_issue.put() flake = Flake.Create(project, step_name, test_name, label) flake.flake_issue_key = flake_issue.key flake.put() analysis = MasterFlakeAnalysis.Create('m', 'b', 123, 's', 't') analysis.flake_key = flake.key analysis.put() mock_comments.return_value = [ Comment({ 'author': { 'name': '*****@*****.**' }, 'content': '', 'published': None, 'id': '12345', }), ] mock_get_issue.return_value = Issue({ 'status': 'Available', 'projectId': 'chromium', 'id': str(bug_id), 'state': 'open' }) flake_analysis_actions.UpdateMonorailBugWithCulprit( analysis.key.urlsafe()) mock_update.assert_called_once_with(bug_id, mock.ANY) self.assertIsNotNone( flake_issue.last_updated_time_with_analysis_results)
def testOnCulpritIdentifiedAttachCulpritFlakeIssue(self, mocked_update_monorail, mocked_merge): project = 'chromium' master_name = 'm' builder_name = 'b' build_number = 123 step_name = 's' test_name = 't' label = 'l' merged_bug_id = 12344 revision = 'r1000' commit_position = 1000 merged_issue = FlakeIssue.Create(project, merged_bug_id) merged_issue.put() flake = Flake.Create(project, step_name, test_name, label) flake.put() culprit = FlakeCulprit.Create(project, revision, commit_position) culprit.flake_issue_key = merged_issue.key culprit.put() analysis = MasterFlakeAnalysis.Create(master_name, builder_name, build_number, step_name, test_name) analysis.flake_key = flake.key analysis.culprit_urlsafe_key = culprit.key.urlsafe() analysis.confidence_in_culprit = 0.9 analysis.put() flake_analysis_actions.OnCulpritIdentified(analysis.key.urlsafe()) self.assertFalse(mocked_merge.called) mocked_update_monorail.assert_called_once_with(analysis.key.urlsafe()) flake = flake.key.get() self.assertEqual(merged_issue.key, flake.flake_issue_key)
def testAnalyzeDetectedFlakeOccurrence(self): step = 'step1' test = 'test1' luci_project = 'chromium' bug_id = 12345 flake = Flake.Create(luci_project, step, test, 'l') flake_issue = FlakeIssue.Create(luci_project, bug_id) flake.flake_issue_key = flake_issue.key occurrence = FlakeOccurrence.Create( flake_type=FlakeType.CQ_FALSE_REJECTION, build_id=111, step_ui_name=step, test_name=test, luci_project=luci_project, luci_bucket='try', luci_builder='tryserver.chromium.linux', legacy_master_name='linux_chromium_rel_ng', legacy_build_number=999, time_happened=None, gerrit_cl_id=98765, parent_flake_key=None) apis.AnalyzeDetectedFlakeOccurrence(flake, occurrence, bug_id) self.assertEqual(1, len(self.taskqueue_requests))
def setUp(self): super(DisplayTestDisablementTest, self).setUp() self.disabled_test1 = LuciTest( key=LuciTest.CreateKey('a', 'b', 'd'), disabled_test_variants={('os:Mac1234', )}, last_updated_time=datetime.datetime(2019, 6, 29, 0, 0, 0), issue_keys=[ndb.Key('FlakeIssue', 'chromium@123')]) self.disabled_test1.put() self.issue_1 = FlakeIssue.Create('chromium', 123) self.issue_1.put() self.disabled_test1_dict = self.disabled_test1.to_dict() self.disabled_test1_dict['disabled_test_variants'] = [ ['os:Mac'], ] self.disabled_test1_dict['issues'] = [{ 'issue_id': 123, 'issue_link': 'https://monorail-prod.appspot.com/p/chromium/issues/detail?id=123', }] self.disabled_test2 = LuciTest( key=LuciTest.CreateKey('a', 'b', 'c'), disabled_test_variants={('os:Mac1234', )}, last_updated_time=datetime.datetime(2019, 6, 29, 0, 0, 0)) self.disabled_test2.put() self.disabled_test2_dict = self.disabled_test2.to_dict() self.disabled_test2_dict['disabled_test_variants'] = [ ['os:Mac'], ] self.disabled_test2_dict['issues'] = [] self.disabled_test3 = LuciTest(key=LuciTest.CreateKey('a', 'b', 'e'), disabled_test_variants=set(), last_updated_time=datetime.datetime( 2019, 6, 29, 0, 0, 0)) self.disabled_test3.put()
def testGetFlakeInformationOldFlakes(self, *_): flake_issue = FlakeIssue.Create(monorail_project='chromium', issue_id=900) flake_issue.last_updated_time_by_flake_detection = datetime(2018, 1, 1) flake_issue.last_updated_time_in_monorail = datetime(2018, 1, 2) flake_issue.status = 'Started' flake_issue.put() luci_project = 'chromium' step_ui_name = 'step' test_name = 'test' normalized_step_name = 'normalized_step_name' normalized_test_name = 'normalized_test_name' test_label_name = 'test_label' flake = Flake.Create( luci_project=luci_project, normalized_step_name=normalized_step_name, normalized_test_name=normalized_test_name, test_label_name=test_label_name, ) flake.component = 'Mock>Component' flake.test_location = TestLocation() flake.test_location.file_path = '../../some/test/path/a.cc' flake.test_location.line_number = 42 flake.flake_issue_key = flake_issue.key flake.put() build_id = 123 luci_bucket = 'try' luci_builder = 'luci builder' legacy_master_name = 'buildbot master' legacy_build_number = 999 time_happened = datetime(2018, 1, 1) gerrit_cl_id = 98765 occurrence = FlakeOccurrence.Create( flake_type=FlakeType.CQ_FALSE_REJECTION, build_id=build_id, step_ui_name=step_ui_name, test_name=test_name, luci_project=luci_project, luci_bucket=luci_bucket, luci_builder=luci_builder, legacy_master_name=legacy_master_name, legacy_build_number=legacy_build_number, time_happened=time_happened, gerrit_cl_id=gerrit_cl_id, parent_flake_key=flake.key) occurrence.time_detected = datetime(2018, 1, 1) occurrence.put() occurrence2 = FlakeOccurrence.Create( flake_type=FlakeType.RETRY_WITH_PATCH, build_id=124, step_ui_name=step_ui_name, test_name=test_name, luci_project=luci_project, luci_bucket=luci_bucket, luci_builder='luci builder 2', legacy_master_name=legacy_master_name, legacy_build_number=legacy_build_number, time_happened=datetime(2018, 1, 2, 3), gerrit_cl_id=gerrit_cl_id, parent_flake_key=flake.key) occurrence2.time_detected = datetime(2018, 1, 2, 3) occurrence2.put() occurrence3 = FlakeOccurrence.Create( flake_type=FlakeType.CQ_FALSE_REJECTION, build_id=125, step_ui_name=step_ui_name, test_name=test_name, luci_project=luci_project, luci_bucket=luci_bucket, luci_builder='luci builder 2', legacy_master_name=legacy_master_name, legacy_build_number=legacy_build_number, time_happened=datetime(2018, 1, 2, 2), gerrit_cl_id=gerrit_cl_id, parent_flake_key=flake.key) occurrence3.time_detected = datetime(2018, 1, 2, 2) occurrence3.put() occurrence4 = FlakeOccurrence.Create( flake_type=FlakeType.CQ_HIDDEN_FLAKE, build_id=126, step_ui_name=step_ui_name, test_name=test_name, luci_project=luci_project, luci_bucket=luci_bucket, luci_builder='luci builder 2', legacy_master_name=legacy_master_name, legacy_build_number=legacy_build_number, time_happened=datetime(2018, 1, 2, 2), gerrit_cl_id=gerrit_cl_id, parent_flake_key=flake.key) occurrence4.time_detected = datetime(2018, 1, 2, 2) occurrence4.put() occurrence5 = FlakeOccurrence.Create( flake_type=FlakeType.CI_FAILED_STEP, build_id=127, step_ui_name=step_ui_name, test_name=test_name, luci_project=luci_project, luci_bucket=luci_bucket, luci_builder='luci builder 2', legacy_master_name=legacy_master_name, legacy_build_number=legacy_build_number, time_happened=datetime(2018, 1, 2, 2), gerrit_cl_id=-1, parent_flake_key=flake.key) occurrence5.time_detected = datetime(2018, 1, 2, 2) occurrence5.put() culprit1 = FlakeCulprit.Create('chromium', 'rev1', 123456, 'culprit_url') culprit1.put() analysis = MasterFlakeAnalysis.Create(legacy_master_name, luci_builder, legacy_build_number, step_ui_name, test_name) analysis.bug_id = 900 analysis.culprit_urlsafe_key = culprit1.key.urlsafe() analysis.confidence_in_culprit = 0.98 analysis.put() culprit2 = FlakeCulprit.Create('chromium', 'rev2', 123457, 'culprit_url') culprit2.put() analysis_1 = MasterFlakeAnalysis.Create(legacy_master_name, luci_builder, legacy_build_number - 1, step_ui_name, test_name) analysis_1.bug_id = 900 analysis_1.culprit_urlsafe_key = culprit2.key.urlsafe() analysis_1.put() expected_flake_dict = { 'luci_project': 'chromium', 'normalized_step_name': 'normalized_step_name', 'normalized_test_name': 'normalized_test_name', 'test_label_name': 'test_label', 'flake_issue_key': flake_issue.key, 'last_occurred_time': None, 'last_test_location_based_tag_update_time': None, 'false_rejection_count_last_week': 0, 'impacted_cl_count_last_week': 0, 'archived': False, 'flake_counts_last_week': [ { 'flake_type': 'cq false rejection', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'cq step level retry', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'cq hidden flake', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'ci failed step', 'impacted_cl_count': 0, 'occurrence_count': 0 }, ], 'flake_score_last_week': 0, 'flake_issue': { 'flake_culprit_key': None, 'monorail_project': 'chromium', 'issue_id': 900, 'last_updated_time_by_flake_detection': datetime(2018, 1, 1), 'issue_link': ('https://monorail-prod.appspot.com/p/chromium/' 'issues/detail?id=900'), 'merge_destination_key': None, 'last_updated_time_in_monorail': '366 days, 00:00:00', 'last_updated_time_with_analysis_results': None, 'create_time_in_monorail': None, 'labels': [], 'status': 'Started', }, 'component': 'Mock>Component', 'test_location': { 'file_path': '../../some/test/path/a.cc', 'line_number': 42, }, 'tags': [], 'culprits': [{ 'revision': 'rev1', 'commit_position': culprit1.commit_position, 'culprit_key': culprit1.key.urlsafe() }], 'sample_analysis': None, 'occurrences': [{ 'group_by_field': 'luci builder 2', 'occurrences': [ { 'flake_type': 'cq step level retry', 'build_id': '124', 'step_ui_name': step_ui_name, 'test_name': test_name, 'tags': [], 'build_configuration': { 'luci_project': 'chromium', 'luci_bucket': 'try', 'luci_builder': 'luci builder 2', 'legacy_master_name': 'buildbot master', 'legacy_build_number': 999 }, 'time_happened': '2018-01-02 03:00:00 UTC', 'time_detected': '2018-01-02 03:00:00 UTC', 'gerrit_cl_id': gerrit_cl_id }, { 'flake_type': 'cq false rejection', 'build_id': '125', 'step_ui_name': step_ui_name, 'test_name': test_name, 'tags': [], 'build_configuration': { 'luci_project': 'chromium', 'luci_bucket': 'try', 'luci_builder': 'luci builder 2', 'legacy_master_name': 'buildbot master', 'legacy_build_number': 999 }, 'time_happened': '2018-01-02 02:00:00 UTC', 'time_detected': '2018-01-02 02:00:00 UTC', 'gerrit_cl_id': gerrit_cl_id }, { 'flake_type': 'ci failed step', 'build_id': '127', 'step_ui_name': step_ui_name, 'test_name': test_name, 'tags': [], 'build_configuration': { 'luci_project': 'chromium', 'luci_bucket': 'try', 'luci_builder': 'luci builder 2', 'legacy_master_name': 'buildbot master', 'legacy_build_number': 999 }, 'time_happened': '2018-01-02 02:00:00 UTC', 'time_detected': '2018-01-02 02:00:00 UTC', 'gerrit_cl_id': -1, }, { 'flake_type': 'cq hidden flake', 'build_id': '126', 'step_ui_name': step_ui_name, 'test_name': test_name, 'tags': [], 'build_configuration': { 'luci_project': 'chromium', 'luci_bucket': 'try', 'luci_builder': 'luci builder 2', 'legacy_master_name': 'buildbot master', 'legacy_build_number': 999 }, 'time_happened': '2018-01-02 02:00:00 UTC', 'time_detected': '2018-01-02 02:00:00 UTC', 'gerrit_cl_id': gerrit_cl_id, }, ] }, { 'group_by_field': 'luci builder', 'occurrences': [{ 'flake_type': 'cq false rejection', 'build_id': '123', 'step_ui_name': step_ui_name, 'test_name': test_name, 'tags': [], 'build_configuration': { 'luci_project': 'chromium', 'luci_bucket': 'try', 'luci_builder': 'luci builder', 'legacy_master_name': 'buildbot master', 'legacy_build_number': 999 }, 'time_happened': '2018-01-01 00:00:00 UTC', 'time_detected': '2018-01-01 00:00:00 UTC', 'gerrit_cl_id': gerrit_cl_id }] }], } self.assertEqual(expected_flake_dict, flake_detection_utils.GetFlakeInformation(flake, 5))
def testGetFlakeInformationClosedIssue(self, *_): flake_issue = FlakeIssue.Create(monorail_project='chromium', issue_id=900) flake_issue.last_updated_time_by_flake_detection = datetime(2018, 1, 1) flake_issue.last_updated_time_in_monorail = datetime(2018, 1, 2) flake_issue.status = 'WontFix' flake_issue.put() luci_project = 'chromium' step_ui_name = 'step' test_name = 'test' normalized_step_name = 'normalized_step_name' normalized_test_name = 'normalized_test_name_3' test_label_name = 'test_label' flake = Flake.Create(luci_project=luci_project, normalized_step_name=normalized_step_name, normalized_test_name=normalized_test_name, test_label_name=test_label_name) flake.flake_issue_key = flake_issue.key flake.put() build_id = 123 luci_bucket = 'try' luci_builder = 'luci builder' legacy_master_name = 'buildbot master' legacy_build_number = 999 time_happened = datetime(2018, 1, 1) gerrit_cl_id = 98765 occurrence = FlakeOccurrence.Create( flake_type=FlakeType.CQ_FALSE_REJECTION, build_id=build_id, step_ui_name=step_ui_name, test_name=test_name, luci_project=luci_project, luci_bucket=luci_bucket, luci_builder=luci_builder, legacy_master_name=legacy_master_name, legacy_build_number=legacy_build_number, time_happened=time_happened, gerrit_cl_id=gerrit_cl_id, parent_flake_key=flake.key) occurrence.time_detected = datetime(2018, 1, 1) occurrence.put() expected_flake_dict = { 'luci_project': 'chromium', 'normalized_step_name': normalized_step_name, 'normalized_test_name': normalized_test_name, 'test_label_name': test_label_name, 'flake_issue_key': flake_issue.key, 'last_occurred_time': None, 'last_test_location_based_tag_update_time': None, 'false_rejection_count_last_week': 0, 'impacted_cl_count_last_week': 0, 'archived': False, 'flake_counts_last_week': [ { 'flake_type': 'cq false rejection', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'cq step level retry', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'cq hidden flake', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'ci failed step', 'impacted_cl_count': 0, 'occurrence_count': 0 }, ], 'flake_score_last_week': 0, 'component': None, 'test_location': None, 'tags': [], 'occurrences': [{ 'group_by_field': 'luci builder', 'occurrences': [{ 'flake_type': 'cq false rejection', 'build_id': '123', 'step_ui_name': step_ui_name, 'test_name': test_name, 'tags': [], 'build_configuration': { 'luci_project': 'chromium', 'luci_bucket': 'try', 'luci_builder': 'luci builder', 'legacy_master_name': 'buildbot master', 'legacy_build_number': 999 }, 'time_happened': '2018-01-01 00:00:00 UTC', 'time_detected': '2018-01-01 00:00:00 UTC', 'gerrit_cl_id': gerrit_cl_id }] }], } self.assertEqual(expected_flake_dict, flake_detection_utils.GetFlakeInformation(flake, 1))
def testShowFlake(self, *_): flake_issue = FlakeIssue.Create(monorail_project='chromium', issue_id=900) flake_issue.last_updated_time_by_flake_detection = datetime(2018, 1, 1) flake_issue.status = 'Assigned' flake_issue.last_updated_time_in_monorail = datetime(2018, 1, 1) flake_issue.put() luci_project = 'chromium' step_ui_name = 'step' test_name = 'test' normalized_step_name = 'normalized_step_name' normalized_test_name = 'normalized_test_name' test_label_name = 'test_label' flake = Flake.Create( luci_project=luci_project, normalized_step_name=normalized_step_name, normalized_test_name=normalized_test_name, test_label_name=test_label_name, ) flake.component = 'Mock>Component' flake.test_location = TestLocation() flake.test_location.file_path = '../../some/test/path/a.cc' flake.test_location.line_number = 42 flake.flake_issue_key = flake_issue.key flake.put() build_id = 123 luci_bucket = 'try' luci_builder = 'luci builder' legacy_master_name = 'buildbot master' legacy_build_number = 999 time_happened = datetime(2018, 1, 1) gerrit_cl_id = 98765 occurrence = FlakeOccurrence.Create( flake_type=FlakeType.CQ_FALSE_REJECTION, build_id=build_id, step_ui_name=step_ui_name, test_name=test_name, luci_project=luci_project, luci_bucket=luci_bucket, luci_builder=luci_builder, legacy_master_name=legacy_master_name, legacy_build_number=legacy_build_number, time_happened=time_happened, gerrit_cl_id=gerrit_cl_id, parent_flake_key=flake.key) occurrence.time_detected = datetime(2018, 1, 1) occurrence.put() response = self.test_app.get('/flake/detection/ui/show-flake', params={ 'key': flake.key.urlsafe(), 'format': 'json', }, status=200) flake_dict = { 'flake_issue': { 'flake_culprit_key': None, 'issue_id': 900, 'issue_link': ('https://monorail-prod.appspot.com/p/chromium/issues' '/detail?id=900'), 'last_updated_time_by_flake_detection': '2018-01-01 00:00:00', 'monorail_project': 'chromium', 'merge_destination_key': None, 'last_updated_time_in_monorail': '2 days, 00:00:00', 'last_updated_time_with_analysis_results': None, 'create_time_in_monorail': None, 'labels': [], 'status': 'Assigned', }, 'flake_issue_key': flake_issue.key, 'luci_project': 'chromium', 'last_occurred_time': None, 'last_test_location_based_tag_update_time': None, 'normalized_step_name': 'normalized_step_name', 'normalized_test_name': 'normalized_test_name', 'test_label_name': 'test_label', 'false_rejection_count_last_week': 0, 'impacted_cl_count_last_week': 0, 'archived': False, 'flake_counts_last_week': [ { 'flake_type': 'cq false rejection', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'cq step level retry', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'cq hidden flake', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'ci failed step', 'impacted_cl_count': 0, 'occurrence_count': 0 }, ], 'flake_score_last_week': 0, 'component': 'Mock>Component', 'tags': [], 'test_location': { 'file_path': '../../some/test/path/a.cc', 'line_number': 42, }, 'culprits': [], 'sample_analysis': None, 'occurrences': [{ 'group_by_field': 'luci builder', 'occurrences': [{ 'build_configuration': { 'legacy_build_number': 999, 'legacy_master_name': 'buildbot master', 'luci_bucket': 'try', 'luci_builder': 'luci builder', 'luci_project': 'chromium' }, 'tags': [], 'build_id': '123', 'flake_type': 'cq false rejection', 'gerrit_cl_id': 98765, 'step_ui_name': 'step', 'test_name': 'test', 'time_detected': '2018-01-01 00:00:00 UTC', 'time_happened': '2018-01-01 00:00:00 UTC' }] }] } self.assertEqual( json.dumps( { 'flake_json': flake_dict, 'key': flake.key.urlsafe(), 'show_all_occurrences': '', 'weights': [('cq false rejection', 100), ('cq step level retry', 10), ('cq hidden flake', 1), ('ci failed step', 10)] }, default=str, sort_keys=True, indent=2), json.dumps(json.loads(response.body), sort_keys=True, indent=2))
def setUp(self): super(RankFlakesTest, self).setUp() self.flake_issue0 = FlakeIssue.Create(monorail_project='chromium', issue_id=900) self.flake_issue0.last_updated_time_in_monorail = datetime.datetime( 2018, 1, 1) self.flake_issue0.status = 'Assigned' self.flake_issue0.last_updated_time_in_monorail = datetime.datetime( 2018, 1, 1) self.flake_issue0.put() self.flake_issue1 = FlakeIssue.Create(monorail_project='chromium', issue_id=1000) self.flake_issue1.last_updated_time_in_monorail = datetime.datetime( 2018, 1, 1) self.flake_issue1.merge_destination_key = self.flake_issue0.key self.flake_issue1.put() self.luci_project = 'chromium' self.normalized_step_name = 'normalized_step_name' self.flake1 = Flake.Create( luci_project=self.luci_project, normalized_step_name=self.normalized_step_name, normalized_test_name='normalized_test_name', test_label_name='normalized_test_name') self.flake1.flake_issue_key = self.flake_issue1.key self.flake1.false_rejection_count_last_week = 3 self.flake1.impacted_cl_count_last_week = 2 self.flake1.flake_score_last_week = 0 self.flake1.last_occurred_time = datetime.datetime(2018, 10, 1) self.flake1.put() self.flake2 = Flake.Create( luci_project=self.luci_project, normalized_step_name=self.normalized_step_name, normalized_test_name='suite.test1', test_label_name='suite.test1') self.flake2.put() self.flake3 = Flake.Create( luci_project=self.luci_project, normalized_step_name=self.normalized_step_name, normalized_test_name='suite.test2', test_label_name='suite.test2') self.flake3.false_rejection_count_last_week = 5 self.flake3.impacted_cl_count_last_week = 3 self.flake3.flake_score_last_week = 10800 self.flake3.last_occurred_time = datetime.datetime(2018, 10, 1) self.flake3.flake_issue_key = self.flake_issue0.key self.flake3.tags = ['suite::suite', 'test_type::flavored_tests'] self.flake3.put() self.flake4 = Flake.Create( luci_project=self.luci_project, normalized_step_name=self.normalized_step_name, normalized_test_name='suite.test3', test_label_name='suite.test3') self.flake4.false_rejection_count_last_week = 5 self.flake4.impacted_cl_count_last_week = 3 self.flake4.flake_score_last_week = 1080 self.flake4.last_occurred_time = datetime.datetime(2018, 10, 1) self.flake4.tags = ['test_type::tests'] self.flake4.put() self.flake5 = Flake.Create( luci_project=self.luci_project, normalized_step_name=self.normalized_step_name, normalized_test_name='suite.test5', test_label_name='suite.test5') self.flake5.false_rejection_count_last_week = 5 self.flake5.impacted_cl_count_last_week = 3 self.flake5.flake_score_last_week = 10800 self.flake5.last_occurred_time = datetime.datetime(2018, 10, 1) self.flake5.flake_issue_key = self.flake_issue0.key self.flake5.tags = ['suite::suite', 'test_type::flavored_tests'] self.flake5.archived = True self.flake5.put() self.flake6 = Flake.Create( luci_project=self.luci_project, normalized_step_name=self.normalized_step_name, normalized_test_name='suite.test6', test_label_name='suite.test6') self.flake6.false_rejection_count_last_week = 5 self.flake6.impacted_cl_count_last_week = 3 self.flake6.flake_score_last_week = 108 self.flake6.last_occurred_time = datetime.datetime(2018, 10, 1) self.flake6.flake_issue_key = self.flake_issue0.key self.flake6.tags = ['suite::suite', 'test_type::flavored_tests'] self.flake6.put() flake_issue0_dict = self.flake_issue0.to_dict() flake_issue0_dict['issue_link'] = FlakeIssue.GetLinkForIssue( self.flake_issue0.monorail_project, self.flake_issue0.issue_id) flake_issue0_dict['last_updated_time_in_monorail'] = ( '274 days, 01:00:00') flake_issue0_dict['status'] = 'Assigned' self.flake1_dict = self.flake1.to_dict() self.flake1_dict['flake_issue'] = flake_issue0_dict self.flake3_dict = self.flake3.to_dict() self.flake3_dict['flake_issue'] = flake_issue0_dict self.flake4_dict = self.flake4.to_dict() self.flake5_dict = self.flake5.to_dict() self.flake5_dict['flake_issue'] = flake_issue0_dict self.flake6_dict = self.flake6.to_dict() self.flake6_dict['flake_issue'] = flake_issue0_dict for data, flake in ((self.flake1_dict, self.flake1), (self.flake3_dict, self.flake3), (self.flake4_dict, self.flake4), (self.flake5_dict, self.flake5), (self.flake6_dict, self.flake6)): data['flake_urlsafe_key'] = flake.key.urlsafe() data['time_delta'] = '1 day, 01:00:00' data['flake_counts_last_week'] = [{ 'flake_type': 'cq false rejection', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'cq step level retry', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'cq hidden flake', 'impacted_cl_count': 0, 'occurrence_count': 0 }, { 'flake_type': 'ci failed step', 'impacted_cl_count': 0, 'occurrence_count': 0 }]