| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import copy | 5 import copy |
| 6 import json | 6 import json |
| 7 import sys | 7 import sys |
| 8 import webapp2 | 8 import webapp2 |
| 9 import webtest | 9 import webtest |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 'diagnostics': { | 27 'diagnostics': { |
| 28 reserved_infos.CHROMIUM_COMMIT_POSITIONS.name: { | 28 reserved_infos.CHROMIUM_COMMIT_POSITIONS.name: { |
| 29 'values': [123], | 29 'values': [123], |
| 30 'type': 'GenericSet' | 30 'type': 'GenericSet' |
| 31 }, | 31 }, |
| 32 reserved_infos.V8_REVISIONS.name: { | 32 reserved_infos.V8_REVISIONS.name: { |
| 33 'values': ['4cd34ad3320db114ad3a2bd2acc02aba004d0cb4'], | 33 'values': ['4cd34ad3320db114ad3a2bd2acc02aba004d0cb4'], |
| 34 'type': 'GenericSet' | 34 'type': 'GenericSet' |
| 35 }, | 35 }, |
| 36 'owners': '68e5b3bd-829c-4f4f-be3a-98a94279ccf0', | 36 'owners': '68e5b3bd-829c-4f4f-be3a-98a94279ccf0', |
| 37 'telemetry': 'ec2c0cdc-cd9f-4736-82b4-6ffc3d76e3eb' | 37 'benchmarks': 'ec2c0cdc-cd9f-4736-82b4-6ffc3d76e3eb' |
| 38 }, | 38 }, |
| 39 'guid': 'c2c0fa00-060f-4d56-a1b7-51fde4767584', | 39 'guid': 'c2c0fa00-060f-4d56-a1b7-51fde4767584', |
| 40 'name': 'foo', | 40 'name': 'foo', |
| 41 'running': [3, 3, 0.5972531564093516, 2, 1, 6, 2], | 41 'running': [3, 3, 0.5972531564093516, 2, 1, 6, 2], |
| 42 'sampleValues': [1, 2, 3], | 42 'sampleValues': [1, 2, 3], |
| 43 'unit': 'count_biggerIsBetter' | 43 'unit': 'count_biggerIsBetter' |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 TEST_TELEMETRY_INFO = { | 47 TEST_BENCHMARKS = { |
| 48 'guid': 'ec2c0cdc-cd9f-4736-82b4-6ffc3d76e3eb', | 48 'guid': 'ec2c0cdc-cd9f-4736-82b4-6ffc3d76e3eb', |
| 49 'benchmarkName': 'myBenchmark', | 49 'values': ['myBenchmark'], |
| 50 'canonicalUrl': 'myCanonicalUrl', | 50 'type': 'GenericSet', |
| 51 'label': 'myLabel', | |
| 52 'legacyTIRLabel': 'myLegacyTIRLabel', | |
| 53 'storyDisplayName': 'myStoryDisplayName', | |
| 54 'type': 'TelemetryInfo' | |
| 55 } | 51 } |
| 56 | 52 |
| 57 | 53 |
| 58 TEST_OWNERS = { | 54 TEST_OWNERS = { |
| 59 'guid': '68e5b3bd-829c-4f4f-be3a-98a94279ccf0', | 55 'guid': '68e5b3bd-829c-4f4f-be3a-98a94279ccf0', |
| 60 'values': ['abc@chromium.org'], | 56 'values': ['abc@chromium.org'], |
| 61 'type': 'GenericSet' | 57 'type': 'GenericSet' |
| 62 } | 58 } |
| 63 | 59 |
| 64 | 60 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 self.assertEqual(1, len(rows)) | 133 self.assertEqual(1, len(rows)) |
| 138 | 134 |
| 139 def testPostHistogram_WithFreshDiagnostics(self): | 135 def testPostHistogram_WithFreshDiagnostics(self): |
| 140 stored_object.Set( | 136 stored_object.Set( |
| 141 add_point_queue.BOT_WHITELIST_KEY, ['win7']) | 137 add_point_queue.BOT_WHITELIST_KEY, ['win7']) |
| 142 test_path = 'Chromium/win7/suite/metric' | 138 test_path = 'Chromium/win7/suite/metric' |
| 143 params = { | 139 params = { |
| 144 'data': json.dumps(TEST_HISTOGRAM), | 140 'data': json.dumps(TEST_HISTOGRAM), |
| 145 'test_path': test_path, | 141 'test_path': test_path, |
| 146 'revision': 123, | 142 'revision': 123, |
| 147 'diagnostics': json.dumps([TEST_TELEMETRY_INFO, TEST_OWNERS]) | 143 'diagnostics': json.dumps([TEST_BENCHMARKS, TEST_OWNERS]) |
| 148 } | 144 } |
| 149 self.testapp.post('/add_histograms_queue', params) | 145 self.testapp.post('/add_histograms_queue', params) |
| 150 histogram_entity = histogram.Histogram.query().fetch()[0] | 146 histogram_entity = histogram.Histogram.query().fetch()[0] |
| 151 hist = histogram_module.Histogram.FromDict(histogram_entity.data) | 147 hist = histogram_module.Histogram.FromDict(histogram_entity.data) |
| 152 self.assertEqual( | 148 self.assertEqual( |
| 153 'ec2c0cdc-cd9f-4736-82b4-6ffc3d76e3eb', | 149 'ec2c0cdc-cd9f-4736-82b4-6ffc3d76e3eb', |
| 154 hist.diagnostics['telemetry'].guid) | 150 hist.diagnostics[reserved_infos.BENCHMARKS.name].guid) |
| 155 self.assertEqual( | 151 self.assertEqual( |
| 156 '68e5b3bd-829c-4f4f-be3a-98a94279ccf0', | 152 '68e5b3bd-829c-4f4f-be3a-98a94279ccf0', |
| 157 hist.diagnostics['owners'].guid) | 153 hist.diagnostics['owners'].guid) |
| 158 telemetry_info_entity = ndb.Key( | 154 telemetry_info_entity = ndb.Key( |
| 159 'SparseDiagnostic', TEST_TELEMETRY_INFO['guid']).get() | 155 'SparseDiagnostic', TEST_BENCHMARKS['guid']).get() |
| 160 ownership_entity = ndb.Key( | 156 ownership_entity = ndb.Key( |
| 161 'SparseDiagnostic', TEST_OWNERS['guid']).get() | 157 'SparseDiagnostic', TEST_OWNERS['guid']).get() |
| 162 self.assertFalse(telemetry_info_entity.internal_only) | 158 self.assertFalse(telemetry_info_entity.internal_only) |
| 163 self.assertFalse(ownership_entity.internal_only) | 159 self.assertFalse(ownership_entity.internal_only) |
| 164 | 160 |
| 165 def testPostHistogram_WithSameDiagnostic(self): | 161 def testPostHistogram_WithSameDiagnostic(self): |
| 166 diag_dict = { | 162 diag_dict = { |
| 167 'guid': '05341937-1272-4214-80ce-43b2d03807f9', | 163 'guid': '05341937-1272-4214-80ce-43b2d03807f9', |
| 168 'benchmarkName': 'myBenchmark', | 164 'values': ['myBenchmark'], |
| 169 'canonicalUrl': 'myCanonicalUrl', | 165 'type': 'GenericSet', |
| 170 'label': 'myLabel', | |
| 171 'legacyTIRLabel': 'myLegacyTIRLabel', | |
| 172 'storyDisplayName': 'myStoryDisplayName', | |
| 173 'type': 'TelemetryInfo' | |
| 174 } | 166 } |
| 175 diag = histogram.SparseDiagnostic( | 167 diag = histogram.SparseDiagnostic( |
| 176 data=diag_dict, start_revision=1, end_revision=sys.maxint, | 168 data=diag_dict, start_revision=1, end_revision=sys.maxint, |
| 177 test=utils.TestKey('Chromium/win7/suite/metric')) | 169 test=utils.TestKey('Chromium/win7/suite/metric')) |
| 178 diag.put() | 170 diag.put() |
| 179 stored_object.Set( | 171 stored_object.Set( |
| 180 add_point_queue.BOT_WHITELIST_KEY, ['win7']) | 172 add_point_queue.BOT_WHITELIST_KEY, ['win7']) |
| 181 test_path = 'Chromium/win7/suite/metric' | 173 test_path = 'Chromium/win7/suite/metric' |
| 182 params = { | 174 params = { |
| 183 'data': json.dumps(TEST_HISTOGRAM), | 175 'data': json.dumps(TEST_HISTOGRAM), |
| 184 'test_path': test_path, | 176 'test_path': test_path, |
| 185 'revision': 123, | 177 'revision': 123, |
| 186 'diagnostics': json.dumps([TEST_TELEMETRY_INFO, TEST_OWNERS]) | 178 'diagnostics': json.dumps([TEST_BENCHMARKS, TEST_OWNERS]) |
| 187 } | 179 } |
| 188 self.testapp.post('/add_histograms_queue', params) | 180 self.testapp.post('/add_histograms_queue', params) |
| 189 histogram_entity = histogram.Histogram.query().fetch()[0] | 181 histogram_entity = histogram.Histogram.query().fetch()[0] |
| 190 hist = histogram_module.Histogram.FromDict(histogram_entity.data) | 182 hist = histogram_module.Histogram.FromDict(histogram_entity.data) |
| 191 self.assertEqual( | 183 self.assertEqual( |
| 192 '05341937-1272-4214-80ce-43b2d03807f9', | 184 TEST_BENCHMARKS['guid'], |
| 193 hist.diagnostics['telemetry'].guid) | 185 hist.diagnostics[reserved_infos.BENCHMARKS.name].guid) |
| 194 diagnostics = histogram.SparseDiagnostic.query().fetch() | 186 diagnostics = histogram.SparseDiagnostic.query().fetch() |
| 195 self.assertEqual(len(diagnostics), 2) | 187 self.assertEqual(len(diagnostics), 3) |
| 196 | 188 |
| 197 def testPostHistogram_WithDifferentDiagnostic(self): | 189 def testPostHistogram_WithDifferentDiagnostic(self): |
| 198 diag_dict = { | 190 diag_dict = { |
| 199 'guid': 'c397a1a0-e289-45b2-abe7-29e638e09168', | 191 'guid': 'c397a1a0-e289-45b2-abe7-29e638e09168', |
| 200 'values': ['def@chromium.org'], | 192 'values': ['def@chromium.org'], |
| 201 'type': 'GenericSet' | 193 'type': 'GenericSet' |
| 202 } | 194 } |
| 203 diag = histogram.SparseDiagnostic( | 195 diag = histogram.SparseDiagnostic( |
| 204 data=diag_dict, start_revision=1, end_revision=sys.maxint, | 196 data=diag_dict, start_revision=1, end_revision=sys.maxint, |
| 205 test=utils.TestKey('Chromium/win7/suite/metric')) | 197 test=utils.TestKey('Chromium/win7/suite/metric')) |
| 206 diag.put() | 198 diag.put() |
| 207 stored_object.Set( | 199 stored_object.Set( |
| 208 add_point_queue.BOT_WHITELIST_KEY, ['win7']) | 200 add_point_queue.BOT_WHITELIST_KEY, ['win7']) |
| 209 test_path = 'Chromium/win7/suite/metric' | 201 test_path = 'Chromium/win7/suite/metric' |
| 210 params = { | 202 params = { |
| 211 'data': json.dumps(TEST_HISTOGRAM), | 203 'data': json.dumps(TEST_HISTOGRAM), |
| 212 'test_path': test_path, | 204 'test_path': test_path, |
| 213 'revision': 123, | 205 'revision': 123, |
| 214 'diagnostics': json.dumps([TEST_TELEMETRY_INFO, TEST_OWNERS]) | 206 'diagnostics': json.dumps([TEST_BENCHMARKS, TEST_OWNERS]) |
| 215 } | 207 } |
| 216 self.testapp.post('/add_histograms_queue', params) | 208 self.testapp.post('/add_histograms_queue', params) |
| 217 histogram_entity = histogram.Histogram.query().fetch()[0] | 209 histogram_entity = histogram.Histogram.query().fetch()[0] |
| 218 hist = histogram_module.Histogram.FromDict(histogram_entity.data) | 210 hist = histogram_module.Histogram.FromDict(histogram_entity.data) |
| 219 self.assertEqual( | 211 self.assertEqual( |
| 220 '68e5b3bd-829c-4f4f-be3a-98a94279ccf0', | 212 '68e5b3bd-829c-4f4f-be3a-98a94279ccf0', |
| 221 hist.diagnostics['owners'].guid) | 213 hist.diagnostics['owners'].guid) |
| 222 diagnostics = histogram.SparseDiagnostic.query().fetch() | 214 diagnostics = histogram.SparseDiagnostic.query().fetch() |
| 223 self.assertEqual(len(diagnostics), 3) | 215 self.assertEqual(len(diagnostics), 3) |
| 224 | 216 |
| 225 def testPostSparseDiagnostic(self): | 217 def testPostSparseDiagnostic(self): |
| 226 stored_object.Set( | 218 stored_object.Set( |
| 227 add_point_queue.BOT_WHITELIST_KEY, ['win7']) | 219 add_point_queue.BOT_WHITELIST_KEY, ['win7']) |
| 228 | 220 |
| 229 test_path = 'Chromium/win7/suite/metric' | 221 test_path = 'Chromium/win7/suite/metric' |
| 230 params = { | 222 params = { |
| 231 'data': json.dumps(TEST_TELEMETRY_INFO), | 223 'data': json.dumps(TEST_BENCHMARKS), |
| 232 'test_path': test_path, | 224 'test_path': test_path, |
| 233 'revision': 123 | 225 'revision': 123 |
| 234 } | 226 } |
| 235 self.testapp.post('/add_histograms_queue', params) | 227 self.testapp.post('/add_histograms_queue', params) |
| 236 | 228 |
| 237 test_key = utils.TestKey(test_path) | 229 test_key = utils.TestKey(test_path) |
| 238 | 230 |
| 239 test = test_key.get() | 231 test = test_key.get() |
| 240 self.assertIsNone(test.units) | 232 self.assertIsNone(test.units) |
| 241 | 233 |
| 242 original_diagnostic = TEST_TELEMETRY_INFO | 234 original_diagnostic = TEST_BENCHMARKS |
| 243 diagnostic_entity = ndb.Key( | 235 diagnostic_entity = ndb.Key( |
| 244 'SparseDiagnostic', original_diagnostic['guid']).get() | 236 'SparseDiagnostic', original_diagnostic['guid']).get() |
| 245 self.assertFalse(diagnostic_entity.internal_only) | 237 self.assertFalse(diagnostic_entity.internal_only) |
| 246 | 238 |
| 247 def testPostSparseDiagnostic_Internal(self): | 239 def testPostSparseDiagnostic_Internal(self): |
| 248 stored_object.Set( | 240 stored_object.Set( |
| 249 add_point_queue.BOT_WHITELIST_KEY, ['mac']) | 241 add_point_queue.BOT_WHITELIST_KEY, ['mac']) |
| 250 | 242 |
| 251 test_path = 'Chromium/win7/suite/metric' | 243 test_path = 'Chromium/win7/suite/metric' |
| 252 test_key = utils.TestKey(test_path) | 244 test_key = utils.TestKey(test_path) |
| 253 | 245 |
| 254 params = { | 246 params = { |
| 255 'data': json.dumps(TEST_TELEMETRY_INFO), | 247 'data': json.dumps(TEST_BENCHMARKS), |
| 256 'test_path': test_path, | 248 'test_path': test_path, |
| 257 'revision': 123 | 249 'revision': 123 |
| 258 } | 250 } |
| 259 self.testapp.post('/add_histograms_queue', params) | 251 self.testapp.post('/add_histograms_queue', params) |
| 260 | 252 |
| 261 test = test_key.get() | 253 test = test_key.get() |
| 262 self.assertIsNone(test.units) | 254 self.assertIsNone(test.units) |
| 263 | 255 |
| 264 original_diagnostic = TEST_TELEMETRY_INFO | 256 original_diagnostic = TEST_BENCHMARKS |
| 265 diagnostic_entity = ndb.Key( | 257 diagnostic_entity = ndb.Key( |
| 266 'SparseDiagnostic', original_diagnostic['guid']).get() | 258 'SparseDiagnostic', original_diagnostic['guid']).get() |
| 267 self.assertTrue(diagnostic_entity.internal_only) | 259 self.assertTrue(diagnostic_entity.internal_only) |
| 268 | 260 |
| 269 def testGetUnitArgs_Up(self): | 261 def testGetUnitArgs_Up(self): |
| 270 unit_args = add_histograms_queue.GetUnitArgs('count_biggerIsBetter') | 262 unit_args = add_histograms_queue.GetUnitArgs('count_biggerIsBetter') |
| 271 self.assertEquals(anomaly.UP, unit_args['improvement_direction']) | 263 self.assertEquals(anomaly.UP, unit_args['improvement_direction']) |
| 272 | 264 |
| 273 def testGetUnitArgs_Down(self): | 265 def testGetUnitArgs_Down(self): |
| 274 unit_args = add_histograms_queue.GetUnitArgs('count_smallerIsBetter') | 266 unit_args = add_histograms_queue.GetUnitArgs('count_smallerIsBetter') |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 339 |
| 348 def testAddRow_FailsWithNonSingularRevisionInfo(self): | 340 def testAddRow_FailsWithNonSingularRevisionInfo(self): |
| 349 test_path = 'Chromium/win7/suite/metric' | 341 test_path = 'Chromium/win7/suite/metric' |
| 350 test_key = utils.TestKey(test_path) | 342 test_key = utils.TestKey(test_path) |
| 351 hist = copy.deepcopy(TEST_HISTOGRAM) | 343 hist = copy.deepcopy(TEST_HISTOGRAM) |
| 352 hist['diagnostics'][reserved_infos.CATAPULT_REVISIONS.name] = { | 344 hist['diagnostics'][reserved_infos.CATAPULT_REVISIONS.name] = { |
| 353 'type': 'GenericSet', 'values': [123, 456]} | 345 'type': 'GenericSet', 'values': [123, 456]} |
| 354 | 346 |
| 355 with self.assertRaises(add_histograms_queue.BadRequestError): | 347 with self.assertRaises(add_histograms_queue.BadRequestError): |
| 356 add_histograms_queue.AddRow(hist, test_key, 123, test_path, False) | 348 add_histograms_queue.AddRow(hist, test_key, 123, test_path, False) |
| OLD | NEW |