def GetFlake(luci_project, original_step_name, original_test_name, master_name, builder_name, build_number): """Returns an existing Flake or creates one as needed. Args: luci_project (str): The project being analyzed, e.g. 'chromium'. original_step_name (str): The original step name which may contain hardware information and 'with(out) patch' etc. suffixes. original_test_name (str): The original test name. master_name (str): Master name of the build of the step. builder_name (str): Builder name of the build of the step. build_number (int): Build number of the build of the step. """ normalized_step_name = Flake.NormalizeStepName(original_step_name, master_name, builder_name, build_number) normalized_test_name = Flake.NormalizeTestName(original_test_name, original_step_name) flake = Flake.Get(luci_project, normalized_step_name, normalized_test_name) if not flake: # pragma: no branch label = Flake.GetTestLabelName(original_test_name, original_step_name) flake = Flake.Create(luci_project, normalized_step_name, normalized_test_name, label) flake.put() return flake
def testNormalizeStepName(self, mocked_get_isolate_target_name, mocked_get_canonical_step_name): self.assertEqual( 'isolate_target_name', Flake.NormalizeStepName( step_name='step_name (with patch) on Android', master_name='m', builder_name='b', build_number=200))
def testNormalizeStepName(self, cases, mock_isolate, mock_canonical): mock_isolate.return_value = cases['isolate_return_value'] mock_canonical.return_value = cases['canonical_return_value'] step_name = Flake.NormalizeStepName(123, 'step_name (with patch)') self.assertEqual(cases['expected_step_name'], step_name) self.assertEqual(cases['isolate_fn_call_count'], mock_isolate.call_count) self.assertEqual(cases['canonical_fn_call_count'], mock_canonical.call_count)
def _CreateLocalTests(row, local_tests, component_mapping, watchlists): """Creates a LuciTest key-test variant pair for a row fetched from BigQuery. Args: row: A row of query results. local_tests (dict): LuciTest entities in local memory in the format {LuciTest.key: {'disabled_test_variants : set(), issue_keys: set()}, mutated by this function. component_mapping (dict): Mapping from directories to crbug components. watchlists (dict): Mapping from directories to watchlists. """ build_id = row['build_id'] builder_name = row['builder_name'] step_name = row['step_name'] test_name = row['test_name'] bugs = row['bugs'] if int(build_id) == 1: # To filter out tests results with invalid build_id. # TODO (crbug.com/999215): Remove this check after test-results is fixed. logging.info( 'Failed to define test variant for build_id: %s, row is %r', build_id, row) return normalized_step_name = Flake.NormalizeStepName(build_id, step_name) normalized_test_name = Flake.NormalizeTestName(test_name, step_name) test_key = LuciTest.CreateKey(_DEFAULT_LUCI_PROJECT, normalized_step_name, normalized_test_name) if not local_tests.get(test_key): local_tests[test_key] = { 'disabled_test_variants': set(), 'issue_keys': set(), 'tags': set() } local_tests[test_key]['tags'].update( _GetNewTestTags(local_tests[test_key]['tags'], step_name, test_name, normalized_step_name, normalized_test_name, build_id, component_mapping, watchlists)) disabled_variant = _CreateDisabledVariant(build_id, builder_name, step_name) local_tests[test_key]['disabled_test_variants'].add(disabled_variant) local_tests[test_key]['issue_keys'].update(_CreateIssueKeys(bugs))
def testNormalizeStepNameForWebkitLayoutTests( self, mocked_get_isolate_target_name, mocked_get_canonical_step_name): self.assertEqual( 'webkit_layout_tests', Flake.NormalizeStepName( step_name='site_per_process_webkit_layout_tests (with patch)', master_name='m', builder_name='b', build_number=200)) # Assertions have never worked properly because we were using mock 1.0.1. # After rolling to mock 2.0.0, which fixes assertions, these assertions now # fail. https://crbug.com/947753. # mocked_get_isolate_target_name.assert_called_once( # master_name='m', # builder_name='b', # build_number=200, # step_name='step_name (with patch) on Android') mocked_get_canonical_step_name.assert_not_called()
def _CreateFlakeFromRow(row): """Creates a Flake entity from a row fetched from BigQuery.""" luci_project = row['luci_project'] luci_builder = row['luci_builder'] legacy_master_name = row['legacy_master_name'] legacy_build_number = row['legacy_build_number'] step_ui_name = row['step_ui_name'] test_name = row['test_name'] normalized_step_name = Flake.NormalizeStepName( step_name=step_ui_name, master_name=legacy_master_name, builder_name=luci_builder, build_number=legacy_build_number) normalized_test_name = Flake.NormalizeTestName(test_name, step_ui_name) test_label_name = Flake.GetTestLabelName(test_name, step_ui_name) return Flake.Create(luci_project=luci_project, normalized_step_name=normalized_step_name, normalized_test_name=normalized_test_name, test_label_name=test_label_name)
def testNormalizeStepNamePartialMatch(self, mock_get_step): Flake.NormalizeStepName(123, 'step_name') self.assertIn(True, mock_get_step.call_args[0]) Flake.NormalizeStepName(123, 'step_name', False) self.assertIn(False, mock_get_step.call_args[0])
def GetStepName(self): return Flake.NormalizeStepName( step_name=self._analysis.step_name, master_name=self._analysis.master_name, builder_name=self._analysis.builder_name, build_number=self._analysis.build_number)
def _CreateFlakeOccurrenceFromRow(row, flake_type_enum): """Creates a FlakeOccurrence from a row fetched from BigQuery.""" luci_project = row['luci_project'] luci_builder = row['luci_builder'] step_ui_name = row['step_ui_name'] test_name = row['test_name'] legacy_master_name = row['legacy_master_name'] legacy_build_number = row['legacy_build_number'] normalized_step_name = Flake.NormalizeStepName( step_name=step_ui_name, master_name=legacy_master_name, builder_name=luci_builder, build_number=legacy_build_number) normalized_test_name = Flake.NormalizeTestName(test_name, step_ui_name) flake_id = Flake.GetId(luci_project=luci_project, normalized_step_name=normalized_step_name, normalized_test_name=normalized_test_name) flake_key = ndb.Key(Flake, flake_id) gerrit_project = row['gerrit_project'] build_id = row['build_id'] luci_bucket = row['luci_bucket'] time_happened = row['test_start_msec'] gerrit_cl_id = row['gerrit_cl_id'] # Not add the original test name as a tag here, because all the tags will be # merged into Flake model, and there might be 100s of parameterized tests # which might lead to too large data for a single Flake entity. tags = [ 'gerrit_project::%s' % gerrit_project, 'luci_project::%s' % luci_project, 'bucket::%s' % luci_bucket, 'master::%s' % legacy_master_name, 'builder::%s' % luci_builder, 'binary::%s' % normalized_step_name, # e.g. "tests" 'test_type::%s' % step_ui_name.split(' ', 1)[0], # e.g. "flavored_tests" 'step::%s' % step_ui_name, # e.g. "flavored_tests on Mac 10.13" 'flake::%s' % normalized_test_name, ] suite = _GetTestSuiteForOccurrence(row, normalized_test_name, normalized_step_name) if suite: tags.append('suite::%s' % suite) tags.sort() flake_occurrence = FlakeOccurrence.Create( flake_type=flake_type_enum, 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, tags=tags) return flake_occurrence