OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 sys | 5 import sys |
6 import unittest | 6 import unittest |
7 | 7 |
8 import mock | 8 import mock |
9 from infra_libs.ts_mon.protos import metrics_pb2 | 9 from infra_libs.ts_mon.protos import metrics_pb2 |
10 | 10 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 m = metrics.CounterMetric('test', fields={'foo': 'bar'}) | 223 m = metrics.CounterMetric('test', fields={'foo': 'bar'}) |
224 m.increment() | 224 m.increment() |
225 p = metrics_pb2.MetricsCollection() | 225 p = metrics_pb2.MetricsCollection() |
226 m.serialize_to(p, 1234, (), m.get(), t) | 226 m.serialize_to(p, 1234, (), m.get(), t) |
227 self.assertEquals(1234000000, p.data[0].start_timestamp_us) | 227 self.assertEquals(1234000000, p.data[0].start_timestamp_us) |
228 | 228 |
229 def test_is_cumulative(self): | 229 def test_is_cumulative(self): |
230 m = metrics.CounterMetric('test') | 230 m = metrics.CounterMetric('test') |
231 self.assertTrue(m.is_cumulative()) | 231 self.assertTrue(m.is_cumulative()) |
232 | 232 |
| 233 def test_get_all(self): |
| 234 m = metrics.CounterMetric('test') |
| 235 m.increment() |
| 236 m.increment({'foo': 'bar'}) |
| 237 m.increment({'foo': 'baz', 'moo': 'wibble'}) |
| 238 self.assertEqual([ |
| 239 ((), 1), |
| 240 ((('foo', 'bar'),), 1), |
| 241 ((('foo', 'baz'), ('moo', 'wibble')), 1), |
| 242 ], sorted(m.get_all())) |
| 243 |
233 | 244 |
234 class GaugeMetricTest(TestBase): | 245 class GaugeMetricTest(TestBase): |
235 | 246 |
236 def test_populate_value(self): | 247 def test_populate_value(self): |
237 pb = metrics_pb2.MetricsData() | 248 pb = metrics_pb2.MetricsData() |
238 m = metrics.GaugeMetric('test') | 249 m = metrics.GaugeMetric('test') |
239 m._populate_value(pb, 1, 1234) | 250 m._populate_value(pb, 1, 1234) |
240 self.assertEquals(pb.gauge, 1) | 251 self.assertEquals(pb.gauge, 1) |
241 | 252 |
242 def test_set(self): | 253 def test_set(self): |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 m.add(25) | 517 m.add(25) |
507 p = metrics_pb2.MetricsCollection() | 518 p = metrics_pb2.MetricsCollection() |
508 m.serialize_to(p, 1234, (), m.get(), t) | 519 m.serialize_to(p, 1234, (), m.get(), t) |
509 self.assertEquals(1234000000, p.data[0].start_timestamp_us) | 520 self.assertEquals(1234000000, p.data[0].start_timestamp_us) |
510 | 521 |
511 def test_is_cumulative(self): | 522 def test_is_cumulative(self): |
512 cd = metrics.CumulativeDistributionMetric('test') | 523 cd = metrics.CumulativeDistributionMetric('test') |
513 ncd = metrics.NonCumulativeDistributionMetric('test2') | 524 ncd = metrics.NonCumulativeDistributionMetric('test2') |
514 self.assertTrue(cd.is_cumulative()) | 525 self.assertTrue(cd.is_cumulative()) |
515 self.assertFalse(ncd.is_cumulative()) | 526 self.assertFalse(ncd.is_cumulative()) |
OLD | NEW |