def testComposite(self):
        external_key = namespaced_stored_object.NamespaceKey(
            update_test_suites.TEST_SUITES_2_CACHE_KEY,
            datastore_hooks.EXTERNAL)
        stored_object.Set(external_key, ['TEST_PARTIAL_TEST_SUITE:COMPOSITE'])
        testing_common.AddTests(
            ['master'], ['bot'], {
                'TEST_PARTIAL_TEST_SUITE': {
                    'COMPOSITE': {
                        'measurement': {
                            'test_case': {},
                        },
                    },
                },
            })
        test = utils.TestKey('master/bot/TEST_PARTIAL_TEST_SUITE/COMPOSITE/' +
                             'measurement/test_case').get()
        test.has_rows = True
        test.put()

        self.Post('/update_test_suite_descriptors')
        self.ExecuteDeferredTasks('default')
        expected = {
            'measurements': ['measurement'],
            'bots': ['master:bot'],
            'cases': ['test_case'],
            'caseTags': {},
        }
        actual = update_test_suite_descriptors.FetchCachedTestSuiteDescriptor(
            'TEST_PARTIAL_TEST_SUITE:COMPOSITE')
        self.assertEqual(expected, actual)
def UpdateDescriptor(test_suite, namespace):
    test_path = descriptor.Descriptor(
        test_suite=test_suite,
        bot='place:holder').ToTestPathsSync()[0].split('/')

    measurements = set()
    bots = set()
    cases = set()
    # TODO(4549) Tagmaps.

    query = graph_data.TestMetadata.query()
    query = query.filter(graph_data.TestMetadata.suite_name == test_path[2])
    if len(test_path) > 3:
        # test_suite is composite.
        query = query.filter(
            graph_data.TestMetadata.test_part1_name == test_path[3])
    query = query.filter(graph_data.TestMetadata.deprecated == False)
    query = query.filter(graph_data.TestMetadata.has_rows == True)
    for key in query.fetch(keys_only=True):
        desc = descriptor.Descriptor.FromTestPathSync(utils.TestPath(key))
        bots.add(desc.bot)
        if desc.measurement:
            measurements.add(desc.measurement)
        if desc.test_case:
            cases.add(desc.test_case)

    desc = {
        'measurements': list(sorted(measurements)),
        'bots': list(sorted(bots)),
        'cases': list(sorted(cases)),
    }
    key = namespaced_stored_object.NamespaceKey(CacheKey(test_suite),
                                                namespace)
    stored_object.Set(key, desc)
예제 #3
0
 def testPostHistogram_WithSameDiagnostic(self):
     diag_dict = {
         'guid': '05341937-1272-4214-80ce-43b2d03807f9',
         'benchmarkName': 'myBenchmark',
         'canonicalUrl': 'myCanonicalUrl',
         'label': 'myLabel',
         'legacyTIRLabel': 'myLegacyTIRLabel',
         'storyDisplayName': 'myStoryDisplayName',
         'type': 'TelemetryInfo'
     }
     diag = histogram.SparseDiagnostic(
         data=diag_dict,
         start_revision=1,
         end_revision=sys.maxint,
         test=utils.TestKey('Chromium/win7/suite/metric'))
     diag.put()
     stored_object.Set(add_point_queue.BOT_WHITELIST_KEY, ['win7'])
     test_path = 'Chromium/win7/suite/metric'
     params = {
         'data': json.dumps(TEST_HISTOGRAM),
         'test_path': test_path,
         'revision': 123,
         'diagnostics': json.dumps([TEST_TELEMETRY_INFO, TEST_OWNERS])
     }
     self.testapp.post('/add_histograms_queue', params)
     histogram_entity = histogram.Histogram.query().fetch()[0]
     hist = histogram_module.Histogram.FromDict(histogram_entity.data)
     self.assertEqual('05341937-1272-4214-80ce-43b2d03807f9',
                      hist.diagnostics['telemetry'].guid)
     diagnostics = histogram.SparseDiagnostic.query().fetch()
     self.assertEqual(len(diagnostics), 2)
예제 #4
0
    def testPostHistogram(self):
        stored_object.Set(add_point_queue.BOT_WHITELIST_KEY, ['win7'])

        test_path = 'Chromium/win7/suite/metric'
        params = {
            'data': json.dumps(TEST_HISTOGRAM),
            'test_path': test_path,
            'revision': 123
        }
        self.testapp.post('/add_histograms_queue', params)

        test_key = utils.TestKey(test_path)

        test = test_key.get()
        self.assertEqual(test.units, 'count_biggerIsBetter')
        self.assertEqual(test.improvement_direction, anomaly.UP)

        master = ndb.Key('Master', 'Chromium').get()
        self.assertIsNotNone(master)

        bot = ndb.Key('Master', 'Chromium', 'Bot', 'win7').get()
        self.assertIsNotNone(bot)

        tests = graph_data.TestMetadata.query().fetch()
        self.assertEqual(2, len(tests))

        histograms = histogram.Histogram.query().fetch()
        self.assertEqual(1, len(histograms))
        self.assertEqual(TEST_HISTOGRAM['guid'], histograms[0].key.id())

        h = histograms[0]
        self.assertEqual(json.dumps(TEST_HISTOGRAM), h.data)
        self.assertEqual(test_key, h.test)
        self.assertEqual(123, h.revision)
        self.assertFalse(h.internal_only)
예제 #5
0
 def testFetchCachedTestSuites_NotEmpty(self):
     # If the cache is set, then whatever's there is returned.
     key = namespaced_stored_object.NamespaceKey(
         update_test_suites._LIST_SUITES_CACHE_KEY)
     stored_object.Set(key, {'foo': 'bar'})
     self.assertEqual({'foo': 'bar'},
                      update_test_suites.FetchCachedTestSuites())
    def testPostHistogram_Internal(self):
        stored_object.Set(add_point_queue.BOT_WHITELIST_KEY, ['mac'])

        test_path = 'Chromium/win7/suite/metric'
        params = [{
            'data': TEST_HISTOGRAM,
            'test_path': test_path,
            'revision': 123
        }]
        self.testapp.post('/add_histograms_queue',
                          {'params': json.dumps(params)})

        test_key = utils.TestKey(test_path)
        original_histogram = TEST_HISTOGRAM

        histograms = histogram.Histogram.query().fetch()
        self.assertEqual(1, len(histograms))
        self.assertEqual(original_histogram['guid'], histograms[0].key.id())

        h = histograms[0]
        h1 = histograms[0].data
        del h1['guid']

        h2 = copy.deepcopy(TEST_HISTOGRAM)
        del h2['guid']
        self.assertEqual(h2, h1)
        self.assertEqual(test_key, h.test)
        self.assertEqual(123, h.revision)
        self.assertTrue(h.internal_only)

        rows = graph_data.Row.query().fetch()
        self.assertEqual(1, len(rows))
 def setUp(self):
     super(UpdateTestSuiteDescriptorsTest, self).setUp()
     handler = update_test_suite_descriptors.UpdateTestSuiteDescriptorsHandler
     self.SetUpApp([('/update_test_suite_descriptors', handler)])
     testing_common.SetIsInternalUser('*****@*****.**', True)
     self.UnsetCurrentUser()
     stored_object.Set(descriptor.PARTIAL_TEST_SUITES_KEY, [
         'TEST_PARTIAL_TEST_SUITE',
     ])
     stored_object.Set(descriptor.COMPOSITE_TEST_SUITES_KEY, [
         'TEST_PARTIAL_TEST_SUITE:COMPOSITE',
     ])
     stored_object.Set(descriptor.GROUPABLE_TEST_SUITE_PREFIXES_KEY, [
         'TEST_GROUPABLE%',
     ])
     descriptor.Descriptor.ResetMemoizedConfigurationForTesting()
예제 #8
0
def UpdateTestSuites(permissions_namespace):
    """Updates test suite data for either internal or external users."""
    logging.info('Updating test suite data for: %s', permissions_namespace)
    suite_dict = _CreateTestSuiteDict()
    key = _NamespaceKey(_LIST_SUITES_CACHE_KEY,
                        namespace=permissions_namespace)
    stored_object.Set(key, suite_dict)
예제 #9
0
 def setUp(self):
     super(ReportQueryTest, self).setUp()
     stored_object.Set(descriptor.PARTIAL_TEST_SUITES_KEY, [])
     stored_object.Set(descriptor.COMPOSITE_TEST_SUITES_KEY, [])
     stored_object.Set(descriptor.GROUPABLE_TEST_SUITE_PREFIXES_KEY, [])
     namespaced_stored_object.Set(bot_configurations.BOT_CONFIGURATIONS_KEY,
                                  {
                                      'a': {
                                          'alias': 'b',
                                      },
                                      'b': {},
                                      'c': {
                                          'alias': 'b',
                                      },
                                  })
     descriptor.Descriptor.ResetMemoizedConfigurationForTesting()
예제 #10
0
def Set(key, value, days_to_keep=None, namespace=None):
  """Sets the value in the datastore.

  Args:
    key: The key name, which will be namespaced.
    value: The value to set.
    days_to_keep: Number of days to keep entity in datastore, default is None.
    Entity will not expire when this value is 0 or None.
    namespace: Optional namespace, otherwise namespace will be retrieved
        using datastore_hooks.GetNamespace().
  """
  # When number of days to keep is given, calculate expiration time for
  # the entity and store it in datastore.
  # Once the entity expires, it will be deleted from the datastore.
  expire_time = None
  if days_to_keep:
    expire_time = datetime.datetime.now() + datetime.timedelta(
        days=days_to_keep)
  namespaced_key = _NamespaceKey(key, namespace)

  try:
    CachedPickledString(id=namespaced_key,
                        value=cPickle.dumps(value),
                        expire_time=expire_time).put()
  except datastore_errors.BadRequestError as e:
    logging.warning('BadRequestError for key %s: %s', key, e)
  except apiproxy_errors.RequestTooLargeError as e:
    stored_object.Set(key, value)
예제 #11
0
 def _AddCachedSuites(self):
     test_suites = {
         'sunspider': {
             'mas': {
                 'ChromiumPerf': {
                     'mac': False,
                     'linux': False
                 }
             },
             'mon': ['Total'],
         },
         'page_cycler': {
             'mas': {
                 'ChromiumPerf': {
                     'linux': False
                 },
                 'CrOS': {
                     'foo': False
                 }
             },
             'mon': ['load_time'],
         },
         'speedometer': {
             'mas': {
                 'CrOS': {
                     'foo': False
                 }
             }
         }
     }
     key = update_test_suites._NamespaceKey(
         update_test_suites._LIST_SUITES_CACHE_KEY)
     stored_object.Set(key, test_suites)
 def testPostHistogram_WithSameDiagnostic(self):
     diag_dict = {
         'guid': '05341937-1272-4214-80ce-43b2d03807f9',
         'values': ['myBenchmark'],
         'type': 'GenericSet',
     }
     diag = histogram.SparseDiagnostic(
         data=diag_dict,
         start_revision=1,
         end_revision=sys.maxint,
         test=utils.TestKey('Chromium/win7/suite/metric'))
     diag.put()
     stored_object.Set(add_point_queue.BOT_WHITELIST_KEY, ['win7'])
     test_path = 'Chromium/win7/suite/metric'
     params = [{
         'data': TEST_HISTOGRAM,
         'test_path': test_path,
         'revision': 123,
         'diagnostics': {
             'benchmarks': TEST_BENCHMARKS,
             'owners': TEST_OWNERS
         }
     }]
     self.testapp.post('/add_histograms_queue',
                       {'params': json.dumps(params)})
     histogram_entity = histogram.Histogram.query().fetch()[0]
     hist = histogram_module.Histogram.FromDict(histogram_entity.data)
     self.assertEqual(TEST_BENCHMARKS['guid'],
                      hist.diagnostics[reserved_infos.BENCHMARKS.name].guid)
     diagnostics = histogram.SparseDiagnostic.query().fetch()
     self.assertEqual(len(diagnostics), 3)
 def testPostHistogram_WithDifferentDiagnostic(self):
     diag_dict = {
         'guid': 'c397a1a0-e289-45b2-abe7-29e638e09168',
         'values': ['*****@*****.**'],
         'type': 'GenericSet'
     }
     diag = histogram.SparseDiagnostic(
         data=diag_dict,
         name='owners',
         start_revision=1,
         end_revision=sys.maxint,
         test=utils.TestKey('Chromium/win7/suite/metric'))
     diag.put()
     stored_object.Set(add_point_queue.BOT_WHITELIST_KEY, ['win7'])
     test_path = 'Chromium/win7/suite/metric'
     params = [{
         'data': TEST_HISTOGRAM,
         'test_path': test_path,
         'revision': 123,
         'diagnostics': {
             'benchmarks': TEST_BENCHMARKS,
             'owners': TEST_OWNERS
         }
     }]
     self.testapp.post('/add_histograms_queue',
                       {'params': json.dumps(params)})
     histogram_entity = histogram.Histogram.query().fetch()[0]
     hist = histogram_module.Histogram.FromDict(histogram_entity.data)
     self.assertEqual('68e5b3bd-829c-4f4f-be3a-98a94279ccf0',
                      hist.diagnostics['owners'].guid)
     diagnostics = histogram.SparseDiagnostic.query().fetch()
     self.assertEqual(len(diagnostics), 3)
 def testPostHistogram_WithFreshDiagnostics(self):
     stored_object.Set(add_point_queue.BOT_WHITELIST_KEY, ['win7'])
     test_path = 'Chromium/win7/suite/metric'
     params = [{
         'data': TEST_HISTOGRAM,
         'test_path': test_path,
         'revision': 123,
         'diagnostics': {
             'benchmarks': TEST_BENCHMARKS,
             'owners': TEST_OWNERS
         }
     }]
     self.testapp.post('/add_histograms_queue',
                       {'params': json.dumps(params)})
     histogram_entity = histogram.Histogram.query().fetch()[0]
     hist = histogram_module.Histogram.FromDict(histogram_entity.data)
     self.assertEqual('ec2c0cdc-cd9f-4736-82b4-6ffc3d76e3eb',
                      hist.diagnostics[reserved_infos.BENCHMARKS.name].guid)
     self.assertEqual('68e5b3bd-829c-4f4f-be3a-98a94279ccf0',
                      hist.diagnostics['owners'].guid)
     telemetry_info_entity = ndb.Key('SparseDiagnostic',
                                     TEST_BENCHMARKS['guid']).get()
     ownership_entity = ndb.Key('SparseDiagnostic',
                                TEST_OWNERS['guid']).get()
     self.assertFalse(telemetry_info_entity.internal_only)
     self.assertEqual('benchmarks', telemetry_info_entity.name)
     self.assertFalse(ownership_entity.internal_only)
     self.assertEqual('owners', ownership_entity.name)
예제 #15
0
 def testPost_CacheSet_ReturnsCachedRevisions(self):
     stored_object.Set(
         'externally_visible__num_revisions_ChromiumPerf/win7/dromaeo/dom',
         [[1, 2, 3]])
     response = self.testapp.post(
         '/graph_revisions', {'test_path': 'ChromiumPerf/win7/dromaeo/dom'})
     self.assertEqual([[1, 2, 3]], json.loads(response.body))
예제 #16
0
 def testPost_CacheSet_NanBecomesNone(self):
     stored_object.Set(
         'externally_visible__num_revisions_ChromiumPerf/win7/dromaeo/dom',
         [[1, 2, 3], [4, float('nan'), 6]])
     response = self.testapp.post(
         '/graph_revisions', {'test_path': 'ChromiumPerf/win7/dromaeo/dom'})
     self.assertEqual([[1, 2, 3], [4, None, 6]], json.loads(response.body))
예제 #17
0
  def testPost_ForcesCacheUpdate(self):
    key = namespaced_stored_object.NamespaceKey(
        update_test_suites._LIST_SUITES_CACHE_KEY)
    stored_object.Set(key, {'foo': 'bar'})
    self.assertEqual({'foo': 'bar'}, update_test_suites.FetchCachedTestSuites())
    self._AddSampleData()
    # Because there is something cached, the cache is
    # not automatically updated when new data is added.
    self.assertEqual({'foo': 'bar'}, update_test_suites.FetchCachedTestSuites())

    stored_object.Set(
        namespaced_stored_object.NamespaceKey(
            update_test_suites.TEST_SUITES_2_CACHE_KEY), ['foo'])
    self.assertEqual(['foo'], update_test_suites.FetchCachedTestSuites2())

    # Making a request to /udate_test_suites forces an update.
    self.testapp.post('/update_test_suites')
    self.assertEqual(
        {
            'dromaeo': {
                'mas': {
                    'Chromium': {
                        'mac': False,
                        'win7': False
                    }
                },
            },
            'scrolling': {
                'mas': {
                    'Chromium': {
                        'mac': False,
                        'win7': False
                    }
                },
            },
            'really': {
                'mas': {
                    'Chromium': {
                        'mac': False,
                        'win7': False
                    }
                },
            },
        }, update_test_suites.FetchCachedTestSuites())

    self.assertEqual(['dromaeo', 'really', 'scrolling'],
                     update_test_suites.FetchCachedTestSuites2())
예제 #18
0
 def setUp(self):
     super(DescriptorTest, self).setUp()
     stored_object.Set(descriptor.PARTIAL_TEST_SUITES_KEY, [
         'TEST_PARTIAL_TEST_SUITE',
     ])
     stored_object.Set(descriptor.COMPOSITE_TEST_SUITES_KEY, [
         'TEST_PARTIAL_TEST_SUITE:COMPOSITE',
     ])
     stored_object.Set(descriptor.GROUPABLE_TEST_SUITE_PREFIXES_KEY, [
         'TEST_GROUPABLE%',
     ])
     stored_object.Set(descriptor.POLY_MEASUREMENT_TEST_SUITES_KEY, [
         'resource_sizes:foo',
         'sizes',
         'polymeasurement',
     ])
     descriptor.Descriptor.ResetMemoizedConfigurationForTesting()
예제 #19
0
 def setUp(self):
     super(BisectFYITest, self).setUp()
     app = webapp2.WSGIApplication([('/bisect_fyi',
                                     bisect_fyi.BisectFYIHandler)])
     self.testapp = webtest.TestApp(app)
     stored_object.Set(bisect_fyi._BISECT_FYI_CONFIGS_KEY, TEST_FYI_CONFIGS)
     testing_common.SetIsInternalUser('*****@*****.**', True)
     self.SetCurrentUser('*****@*****.**')
예제 #20
0
 def testSetAndGet_CacheNotExist_CacheSet(self):
   new_account = SampleSerializableClass('Some account data.')
   stored_object.Set('chris', new_account)
   stored_object.MultipartCache.Delete('chris')
   chris_account = stored_object.Get('chris')
   self.assertEqual(new_account, chris_account)
   cache_values = self._GetCachedValues('chris')
   self.assertGreater(len(cache_values), 0)
예제 #21
0
 def _Start(self, query):
   status = {
       'count': 0,
       'started': datetime.datetime.now().isoformat(),
       'total': query.count(),
   }
   stored_object.Set(_STATUS_KEY, status)
   taskqueue.add(url='/api/migrate')
예제 #22
0
  def testSetAndGet_NoMemcache(self, async_mock):
    async_mock.return_value = ndb.Future()
    async_mock.return_value.set_result(None)

    new_account = SampleSerializableClass('Some account data.')
    stored_object.Set('chris', new_account)
    chris_account = stored_object.Get('chris')
    self.assertEqual(new_account, chris_account)
예제 #23
0
  def setUp(self):
    super(ReportTemplateTest, self).setUp()
    stored_object.Set(descriptor.PARTIAL_TEST_SUITES_KEY, [])
    stored_object.Set(descriptor.COMPOSITE_TEST_SUITES_KEY, [])
    stored_object.Set(descriptor.GROUPABLE_TEST_SUITE_PREFIXES_KEY, [])
    descriptor.Descriptor.ResetMemoizedConfigurationForTesting()

    report_template.ReportTemplate(
        id='ex-id',
        name='external',
        owners=[testing_common.EXTERNAL_USER.email()],
        template={'rows': [], 'statistics': ['avg']}).put()
    report_template.ReportTemplate(
        internal_only=True,
        name='internal',
        id='in-id',
        owners=[testing_common.INTERNAL_USER.email()],
        template={'rows': [], 'statistics': ['avg']}).put()
예제 #24
0
  def testPost_DiagnosticsInternalOnly_True(self):
    stored_object.Set(
        add_point_queue.BOT_WHITELIST_KEY, ['not_in_list'])

    self._TestDiagnosticsInternalOnly()

    diagnostics = histogram.SparseDiagnostic.query().fetch()
    for d in diagnostics:
      self.assertTrue(d.internal_only)
예제 #25
0
 def testPost_WithSomeInvalidJSON_ShowsErrorAndDoesNotModify(self):
   stored_object.Set('foo', 'XXX')
   response = self.testapp.post('/edit_site_config', {
       'key': 'foo',
       'value': '[1, 2, this is not json',
       'xsrf_token': xsrf.GenerateToken(users.get_current_user()),
   })
   self.assertIn('Invalid JSON', response.body)
   self.assertEqual('XXX', stored_object.Get('foo'))
예제 #26
0
    def setUp(self):
        super(_NewTest, self).setUp()

        self.SetCurrentUserOAuth(testing_common.INTERNAL_USER)
        self.SetCurrentClientIdOAuth(api_auth.OAUTH_CLIENT_ID_WHITELIST[0])

        key = namespaced_stored_object.NamespaceKey('bot_configurations',
                                                    datastore_hooks.INTERNAL)
        stored_object.Set(key,
                          {'chromium-rel-mac11-pro': _CONFIGURATION_ARGUMENTS})
예제 #27
0
    def _Migrate(self, query, status):
        cursor = datastore_query.Cursor(urlsafe=self.request.get('cursor'))
        jobs, next_cursor, more = query.fetch_page(_BATCH_SIZE,
                                                   start_cursor=cursor)
        for j in jobs:
            _MigrateJob(j)
        try:
            ndb.put_multi(jobs)
        except datastore_errors.BadRequestError as e:
            logging.critical(e)
            logging.critical([j.job_id for j in jobs])

        if more:
            status['count'] += len(jobs)
            stored_object.Set(_STATUS_KEY, status)
            params = {'cursor': next_cursor.urlsafe()}
            taskqueue.add(url='/api/migrate', params=params)
        else:
            stored_object.Set(_STATUS_KEY, None)
예제 #28
0
def _Start():
    query = job.Job.query(job.Job.task == None)
    status = {
        'count': 0,
        'started': datetime.datetime.now().isoformat(),
        'total': query.count(),
        'errors': 0,
    }
    stored_object.Set(_STATUS_KEY, status)
    deferred.defer(_Migrate, status, None)
    def testCaseTags(self):
        external_key = namespaced_stored_object.NamespaceKey(
            update_test_suites.TEST_SUITES_2_CACHE_KEY,
            datastore_hooks.EXTERNAL)
        stored_object.Set(external_key, ['suite'])
        testing_common.AddTests(['master'], ['a', 'b'], {
            'suite': {
                'measurement': {
                    'x': {},
                    'y': {},
                    'z': {},
                },
            },
        })
        for bot in 'ab':
            for case in 'xyz':
                test = utils.TestKey('master/%s/suite/measurement/%s' %
                                     (bot, case)).get()
                test.has_rows = True
                test.put()
        histogram.SparseDiagnostic(test=utils.TestKey('master/a/suite'),
                                   name=reserved_infos.TAG_MAP.name,
                                   end_revision=sys.maxint,
                                   data=histogram_module.TagMap({
                                       'tagsToStoryNames': {
                                           'j': ['x']
                                       }
                                   }).AsDict()).put()
        histogram.SparseDiagnostic(test=utils.TestKey('master/b/suite'),
                                   name=reserved_infos.TAG_MAP.name,
                                   end_revision=sys.maxint,
                                   data=histogram_module.TagMap({
                                       'tagsToStoryNames': {
                                           'j': ['y'],
                                           'k': ['y']
                                       }
                                   }).AsDict()).put()

        self.Post('/update_test_suite_descriptors')

        self.ExecuteDeferredTasks('default')

        expected = {
            'measurements': ['measurement'],
            'bots': ['master:a', 'master:b'],
            'cases': ['x', 'y', 'z'],
            'caseTags': {
                'j': ['x', 'y'],
                'k': ['y']
            },
        }
        actual = update_test_suite_descriptors.FetchCachedTestSuiteDescriptor(
            'suite')
        self.assertEqual(expected, actual)
예제 #30
0
  def testDelete_LargeObject_AllEntitiesDeleted(self):
    a_large_string = '0' * 2097152
    new_account = SampleSerializableClass(a_large_string)
    stored_object.Set('chris', new_account)

    stored_object.Delete('chris')

    multipart_entities = stored_object.MultipartEntity.query().fetch()
    self.assertEqual(0, len(multipart_entities))
    part_entities = stored_object.PartEntity.query().fetch()
    self.assertEqual(0, len(part_entities))