Exemplo n.º 1
0
    def testCreateStoppageAlert_DoesNotCreateLargeGroups(self):
        # First, create |_MAX_GROUP_SIZE| alerts; all of them can be created
        # and they all belong to the same group.
        tests = map(str, range(stoppage_alert._MAX_GROUP_SIZE))
        testing_common.AddTests(['M'], ['b'],
                                {'suite': {t: {}
                                           for t in tests}})
        test_paths = ['M/b/suite/' + t for t in tests]
        rows = []
        alerts = []
        for path in test_paths:
            rows = testing_common.AddRows(path, [1])
            test = utils.TestKey(path).get()
            new_alert = stoppage_alert.CreateStoppageAlert(test, rows[0])
            self.assertIsNotNone(new_alert)
            new_alert.put()
            alerts.append(new_alert)
        self.assertEqual(stoppage_alert._MAX_GROUP_SIZE, len(alerts))
        self.assertTrue(all(a.group == alerts[0].group for a in alerts))

        # Making one more stoppage alert that belongs to this group fails.
        testing_common.AddTests(['M'], ['b'], {'suite': {'another': {}}})
        test_path = 'M/b/suite/another'
        rows = testing_common.AddRows(test_path, [1])
        test = utils.TestKey(test_path).get()
        new_alert = stoppage_alert.CreateStoppageAlert(test, rows[0])
        self.assertIsNone(new_alert)
 def testGet_ThreeAlertsOneSheriff_EmailSent(self):
     self._AddSampleData()
     for name in ('foo', 'bar', 'baz'):
         test = utils.TestKey('M/b/suite/%s' % name).get()
         row = graph_data.Row.query(graph_data.Row.parent_test ==
                                    utils.OldStyleTestKey(test.key)).get()
         stoppage_alert.CreateStoppageAlert(test, row).put()
     self.testapp.get('/send_stoppage_alert_emails')
     messages = self.mail_stub.get_sent_messages()
     self.assertEqual(1, len(messages))
     self.assertEqual('*****@*****.**', messages[0].sender)
     self.assertEqual('*****@*****.**', messages[0].to)
     self.assertIn('3', messages[0].subject)
     body = str(messages[0].body)
     self.assertIn('foo', body)
     self.assertIn('bar', body)
     self.assertIn('baz', body)
     self.assertIn(
         'http://build.chromium.org/p/chromium.perf/builders/Mac/builds/187',
         body)
     self.assertIn(
         'http://build.chromium.org/p/chromium.perf/builders/Win/builds/184',
         body)
     self.assertIn(
         'https://luci-logdog.appspot.com/v/?s=chrome%2Fbb%2Fchromium.perf%2F'
         'Win%2F184%2F%2B%2Frecipes%2Fsteps%2Fmedia.mse_cases%2F0%2Fstdout',
         body)
     stoppage_alerts = stoppage_alert.StoppageAlert.query().fetch()
     for alert in stoppage_alerts:
         self.assertTrue(alert.mail_sent)
Exemplo n.º 3
0
    def testPost_MigratesStoppageAlerts(self):
        testing_common.AddTests(['Master'], ['b'], {'suite': {'foo': {}}})
        test_path = 'Master/b/suite/foo'
        test_key = utils.TestKey(test_path)
        test_container_key = utils.GetTestContainerKey(test_key)
        row_key = graph_data.Row(id=100, parent=test_container_key,
                                 value=5).put()
        stoppage_alert.CreateStoppageAlert(test_key.get(), row_key.get()).put()
        self.assertIsNotNone(
            stoppage_alert.GetStoppageAlert('Master/b/suite/foo', 100))
        self.assertIsNone(
            stoppage_alert.GetStoppageAlert('Master/b/suite/bar', 100))

        self.testapp.post(
            '/migrate_test_names', {
                'old_pattern': 'Master/b/suite/foo',
                'new_pattern': 'Master/b/suite/bar',
            })
        self.ExecuteTaskQueueTasks('/migrate_test_names',
                                   migrate_test_names._TASK_QUEUE_NAME)

        self.assertIsNotNone(
            stoppage_alert.GetStoppageAlert('Master/b/suite/bar', 100))
        self.assertIsNone(
            stoppage_alert.GetStoppageAlert('Master/b/suite/foo', 100))
Exemplo n.º 4
0
    def testPost_DeprecateOldTest_ExistingStoppageAlert_NoAlert(
            self, mock_delete):
        sheriff.Sheriff(id='ref_sheriff',
                        email='*****@*****.**',
                        patterns=['*/*/*/*', '*/*/*/*/*'],
                        stoppage_alert_delay=1).put()

        testing_common.AddTests(*_TESTS_SIMPLE)

        self._AddMockRows('ChromiumPerf/mac/SunSpider/Total/t',
                          _DEPRECATE_DAYS)
        self._AddMockRows('ChromiumPerf/mac/SunSpider/Total/t_ref', 0)

        test_path = 'ChromiumPerf/mac/SunSpider/Total/t'
        test_key = utils.TestKey(test_path)
        test_parent = utils.OldStyleTestKey(test_key)
        query = graph_data.Row.query(graph_data.Row.parent_test == test_parent)
        query = query.order(-graph_data.Row.timestamp)
        last_row = query.get()

        stoppage_alert.CreateStoppageAlert(test_key.get(), last_row).put()

        self.testapp.post('/deprecate_tests')
        self.ExecuteTaskQueueTasks(
            '/deprecate_tests',
            deprecate_tests._DEPRECATE_TESTS_TASK_QUEUE_NAME)

        self.AssertDeprecated('ChromiumPerf/mac/SunSpider/Total/t', True)
        self.AssertDeprecated('ChromiumPerf/mac/SunSpider/Total/t_ref', False)

        self.assertFalse(mock_delete.called)

        alerts = stoppage_alert.StoppageAlert.query().fetch()
        self.assertEqual(1, len(alerts))
Exemplo n.º 5
0
def _CreateStoppageAlerts(test, last_row):
    """Yields put operations for any StoppageAlert that may be created.

  A stoppage alert is an alert created to warn people that data has not
  been received for a particular test for some length of time. An alert
  will only be created if the stoppage_alert_delay property of the sheriff
  is non-zero -- the value of this property is the number of days that should
  pass before an alert is created.

  Args:
    test: A Test entity.
    last_row: The Row entity that was last added.

  Yields:
    Either one op.db.Put, or nothing.
  """
    if not test.sheriff:
        return
    sheriff_entity = test.sheriff.get()
    warn_sheriff_delay_days = sheriff_entity.stoppage_alert_delay
    if warn_sheriff_delay_days < 0:
        return

    now = datetime.datetime.now()
    warn_sheriff_delta = datetime.timedelta(days=warn_sheriff_delay_days)
    earliest_warn_time = now - warn_sheriff_delta
    if last_row.timestamp < earliest_warn_time:
        if not stoppage_alert.GetStoppageAlert(test.test_path,
                                               last_row.revision):
            yield op.db.Put(stoppage_alert.CreateStoppageAlert(test, last_row))
Exemplo n.º 6
0
 def testGet_WithStoppageAlert_ChangesAlertBugId(self):
     test_keys = self._AddTests()
     rows = testing_common.AddRows(utils.TestPath(test_keys[0]), {10, 20})
     alert_key = stoppage_alert.CreateStoppageAlert(test_keys[0].get(),
                                                    rows[0]).put()
     self.testapp.get('/associate_alerts?bug_id=123&keys=%s' %
                      alert_key.urlsafe())
     self.assertEqual(123, alert_key.get().bug_id)
Exemplo n.º 7
0
 def testDeprecateTestsMapper_AlreadyHasAlert_NoNewStoppageAlert(self):
     test_key, row_key, _ = self._AddTestRowSheriff(row_age_days=8,
                                                    stoppage_alert_delay=6)
     self.assertIsNone(stoppage_alert.StoppageAlert.query().get())
     stoppage_alert.CreateStoppageAlert(test_key.get(), row_key.get()).put()
     self.assertEqual(1, len(stoppage_alert.StoppageAlert.query().fetch()))
     for operation in mr.DeprecateTestsMapper(test_key.get()):
         self._ExecOperation(operation)
     self.assertEqual(1, len(stoppage_alert.StoppageAlert.query().fetch()))
Exemplo n.º 8
0
 def _AddStoppageAlerts(self):
     testing_common.AddTests(
         ['ChromiumGPU'], ['linux-release'],
         {'scrolling_benchmark': {
             'dropped_foo': {},
             'dropped_bar': {},
         }})
     foo_path = 'ChromiumGPU/linux-release/scrolling_benchmark/dropped_foo'
     bar_path = 'ChromiumGPU/linux-release/scrolling_benchmark/dropped_bar'
     foo_test = utils.TestKey(foo_path).get()
     bar_test = utils.TestKey(bar_path).get()
     foo_row = testing_common.AddRows(foo_path, {200})[0]
     bar_row = testing_common.AddRows(bar_path, {200})[0]
     foo_alert_key = stoppage_alert.CreateStoppageAlert(foo_test,
                                                        foo_row).put()
     bar_alert_key = stoppage_alert.CreateStoppageAlert(bar_test,
                                                        bar_row).put()
     return [foo_alert_key.get(), bar_alert_key.get()]
Exemplo n.º 9
0
 def testPost_WithBugIdParameter_ListsStoppageAlerts(self):
     test_keys = self._AddTests()
     bug_data.Bug(id=123).put()
     row = testing_common.AddRows(utils.TestPath(test_keys[0]), {100})[0]
     alert = stoppage_alert.CreateStoppageAlert(test_keys[0].get(), row)
     alert.bug_id = 123
     alert.put()
     response = self.testapp.post('/group_report?bug_id=123')
     alert_list = self.GetJsonValue(response, 'alert_list')
     self.assertEqual(1, len(alert_list))
Exemplo n.º 10
0
 def testGetOrCreateAncestors_UpdatesStoppageAlert(self):
     testing_common.AddTests(['M'], ['b'], {'suite': {'foo': {}}})
     row = testing_common.AddRows('M/b/suite/foo', {123})[0]
     test = utils.TestKey('M/b/suite/foo').get()
     alert_key = stoppage_alert.CreateStoppageAlert(test, row).put()
     test.stoppage_alert = alert_key
     test.put()
     add_point_queue._GetOrCreateAncestors('M', 'b', 'suite/foo')
     self.assertIsNone(test.key.get().stoppage_alert)
     self.assertTrue(alert_key.get().recovered)
Exemplo n.º 11
0
 def testPost_StoppageAlerts_EmbedsStoppageAlertListAndOneTable(self):
   sheriff.Sheriff(id='Sheriff', patterns=['M/b/*/*']).put()
   testing_common.AddTests(['M'], ['b'], {'foo': {'bar': {}}})
   test_key = utils.TestKey('M/b/foo/bar')
   rows = testing_common.AddRows('M/b/foo/bar', {9800, 9802})
   for row in rows:
     stoppage_alert.CreateStoppageAlert(test_key.get(), row).put()
   response = self.testapp.post('/alerts?sheriff=Sheriff')
   stoppage_alert_list = self.GetJsonValue(response, 'stoppage_alert_list')
   self.assertEqual(2, len(stoppage_alert_list))
Exemplo n.º 12
0
 def testPost_WithBugIdParameter_ListsStoppageAlerts(self, mock_oauth):
     self._SetGooglerOAuth(mock_oauth)
     test_keys = self._AddTests()
     bug_data.Bug(id=123).put()
     row = testing_common.AddRows(utils.TestPath(test_keys[0]), {100})[0]
     alert = stoppage_alert.CreateStoppageAlert(test_keys[0].get(), row)
     alert.bug_id = 123
     alert.put()
     response = self.testapp.post('/api/alerts/bug_id/123')
     stoppage_alerts = self.GetJsonValue(response, 'stoppage_alerts')
     self.assertEqual(1, len(stoppage_alerts))
Exemplo n.º 13
0
 def testGet_StoppageAlerts_EmbedsStoppageAlertListAndOneTable(self):
     sheriff.Sheriff(id='Sheriff', patterns=['M/b/*/*']).put()
     testing_common.AddTests(['M'], ['b'], {'foo': {'bar': {}}})
     test_key = utils.TestKey('M/b/foo/bar')
     rows = testing_common.AddRows('M/b/foo/bar', {9800, 9802})
     for row in rows:
         stoppage_alert.CreateStoppageAlert(test_key.get(), row).put()
     response = self.testapp.get('/alerts?sheriff=Sheriff')
     stoppage_alert_list = self.GetEmbeddedVariable(response,
                                                    'STOPPAGE_ALERT_LIST')
     self.assertEqual(2, len(stoppage_alert_list))
     self.assertEqual(1, len(response.html('alerts-table')))
Exemplo n.º 14
0
 def testPost_StoppageAlertWithBogusRow_LogsErrorAndShowsTable(
     self, mock_logging_error):
   sheriff.Sheriff(id='Sheriff', patterns=['M/b/*/*']).put()
   testing_common.AddTests(['M'], ['b'], {'foo': {'bar': {}}})
   test_key = utils.TestKey('M/b/foo/bar')
   row_parent = utils.GetTestContainerKey(test_key)
   row = graph_data.Row(parent=row_parent, id=1234)
   stoppage_alert.CreateStoppageAlert(test_key.get(), row).put()
   response = self.testapp.post('/alerts?sheriff=Sheriff')
   stoppage_alert_list = self.GetJsonValue(response, 'stoppage_alert_list')
   self.assertEqual(1, len(stoppage_alert_list))
   self.assertEqual(1, mock_logging_error.call_count)
Exemplo n.º 15
0
 def testCreateStoppageAlert_Basic(self):
     test, row = self._AddSampleData()
     alert = stoppage_alert.CreateStoppageAlert(test, row)
     alert.put()
     self.assertFalse(alert.internal_only)
     self.assertEqual(test.sheriff, alert.sheriff)
     self.assertEqual(test.key, alert.test)
     self.assertEqual(row.revision, alert.revision)
     self.assertEqual(row.revision, alert.start_revision)
     self.assertEqual(row.revision, alert.end_revision)
     self.assertFalse(alert.mail_sent)
     self.assertIsNone(alert.bug_id)
     self.assertIsNotNone(alert.timestamp)
Exemplo n.º 16
0
 def testCreateStoppageAlert_DisplayRevIfClank(self):
     testing_common.AddTests(['ClankInternal'], ['b'],
                             {'suite': {
                                 'foo': {}
                             }})
     sheriff.Sheriff(id='Foo', patterns=['*/*/*/*']).put()
     test_path = 'ClankInternal/b/suite/foo'
     test_key = utils.TestKey(test_path)
     test = test_key.get()
     testing_common.AddRows(test_path, {100})
     row = graph_data.Row.query().get()
     row.r_commit_pos = 102
     alert = stoppage_alert.CreateStoppageAlert(test, row)
     self.assertEqual(alert.display_start, 102)
     self.assertEqual(alert.display_end, 102)
 def testGet_ThreeAlertsOneSheriff_EmailSent(self):
     self._AddSampleData()
     for name in ('foo', 'bar', 'baz'):
         test = utils.TestKey('M/b/suite/%s' % name).get()
         row = graph_data.Row.query(graph_data.Row.parent_test ==
                                    utils.OldStyleTestKey(test.key)).get()
         stoppage_alert.CreateStoppageAlert(test, row).put()
     self.testapp.get('/send_stoppage_alert_emails')
     messages = self.mail_stub.get_sent_messages()
     self.assertEqual(1, len(messages))
     self.assertEqual('*****@*****.**', messages[0].sender)
     self.assertEqual('*****@*****.**', messages[0].to)
     self.assertIn('3', messages[0].subject)
     self.assertIn('foo', str(messages[0].body))
     self.assertIn('bar', str(messages[0].body))
     self.assertIn('baz', str(messages[0].body))
     stoppage_alerts = stoppage_alert.StoppageAlert.query().fetch()
     for alert in stoppage_alerts:
         self.assertTrue(alert.mail_sent)
Exemplo n.º 18
0
 def _AddDataToDataStore(self):
     testing_common.AddTests(['ChromiumPerf'], ['win'],
                             {'sunspider': {
                                 'Total': {}
                             }})
     test = utils.TestKey('ChromiumPerf/win/sunspider/Total').get()
     test_container_key = utils.GetTestContainerKey(test)
     row = graph_data.Row(id=345,
                          buildnumber=456,
                          parent=test_container_key)
     # Test buildbot format
     row.a_stdio_uri = ('[Buildbot stdio]('
                        'http://build.chromium.org/p/my.master.id/'
                        'builders/MyBuilder%20%281%29/builds/456/steps/'
                        'sunspider/logs/stdio)')
     row.put()
     alert = stoppage_alert.CreateStoppageAlert(test, row)
     alert.put()
     return test, row, alert
Exemplo n.º 19
0
def _CreateStoppageAlerts(test_key, last_row_key):
    """Creates a StoppageAlert for the test.

  A stoppage alert is an alert created to warn people that data has not
  been received for a particular test for some length of time. An alert
  will only be created if the stoppage_alert_delay property of the sheriff
  is non-zero -- the value of this property is the number of days that should
  pass before an alert is created.

  Args:
    test_key: A TestMetadata entity key.
    last_row_key: The Row entity key that was last added.
  Return:
    True, if we should create a stoppage alert, False otherwise.
  """
    logging.info("_CreateStoppageAlerts: [%s, %s]", str(test_key.id()),
                 str(last_row_key.id()))
    test = test_key.get()
    last_row = last_row_key.get()

    new_alert = stoppage_alert.CreateStoppageAlert(test, last_row)
    if not new_alert:
        return
    new_alert.put()
Exemplo n.º 20
0
 def testGetStoppageAlert_EntityExists_ReturnsEntity(self):
     test, row = self._AddSampleData()
     stoppage_alert.CreateStoppageAlert(test, row).put()
     self.assertIsNotNone(
         stoppage_alert.GetStoppageAlert(test.test_path, row.revision))
Exemplo n.º 21
0
 def testPutMultipleTimes_OnlyOneEntityPut(self):
     test, row = self._AddSampleData()
     stoppage_alert.CreateStoppageAlert(test, row).put()
     stoppage_alert.CreateStoppageAlert(test, row).put()
     self.assertEqual(1, len(stoppage_alert.StoppageAlert.query().fetch()))
Exemplo n.º 22
0
 def testCreateStoppageAlert_InternalOnly(self):
     test, row = self._AddSampleData()
     test.internal_only = True
     test.put()
     alert = stoppage_alert.CreateStoppageAlert(test, row)
     self.assertTrue(alert.internal_only)