Exemplo n.º 1
0
def ProcessTest(test_key):
    """Processes a test to find new anomalies.

  Args:
    test_key: The ndb.Key for a TestMetadata.
  """
    test = test_key.get()
    config = anomaly_config.GetAnomalyConfigDict(test)
    max_num_rows = config.get('max_window_size', DEFAULT_NUM_POINTS)
    rows = GetRowsToAnalyze(test, max_num_rows)
    # If there were no rows fetched, then there's nothing to analyze.
    if not rows:
        # In some cases (e.g. if some points are deleted) it might be possible
        # that last_alerted_revision is incorrect. In this case, reset it.
        highest_rev = _HighestRevision(test_key)
        if test.last_alerted_revision > highest_rev:
            logging.error(
                'last_alerted_revision %d is higher than highest rev %d '
                'for test %s; setting last_alerted_revision to None.',
                test.last_alerted_revision, highest_rev, test.test_path)
            test.last_alerted_revision = None
            test.put()
        logging.error('No rows fetched for %s', test.test_path)
        return

    test = test_key.get()
    sheriff = _GetSheriffForTest(test)
    if not sheriff:
        logging.error('No sheriff for %s', test_key)
        return

    # Get anomalies and check if they happen in ref build also.
    change_points = FindChangePointsForTest(rows, config)
    change_points = _FilterAnomaliesFoundInRef(change_points, test_key,
                                               len(rows))

    anomalies = [_MakeAnomalyEntity(c, test, rows) for c in change_points]

    # If no new anomalies were found, then we're done.
    if not anomalies:
        return

    logging.info('Found at least one anomaly in: %s', test.test_path)

    # Update the last_alerted_revision property of the test.
    test.last_alerted_revision = anomalies[-1].end_revision
    test.put()

    alert_group.GroupAlerts(anomalies, utils.TestSuiteName(test.key),
                            'Anomaly')

    # Email sheriff about any new regressions.
    for anomaly_entity in anomalies:
        if (anomaly_entity.bug_id is None and not anomaly_entity.is_improvement
                and not sheriff.summarize):
            email_sheriff.EmailSheriff(sheriff, test, anomaly_entity)

    ndb.put_multi(anomalies)
Exemplo n.º 2
0
 def testTestSuiteName_KeyNotLongEnough_ReturnsNone(self):
     key = ndb.Key('Master', 'M', 'Bot', 'b')
     self.assertIsNone(utils.TestSuiteName(key))
Exemplo n.º 3
0
 def testTestSuiteName_Basic(self):
     key = utils.TestKey('Master/bot/suite-foo/sub/x/y/z')
     self.assertEqual('suite-foo', utils.TestSuiteName(key))