def test_distribution(self): # Create some fake metrics. dog = ThreadStats() dog.start(roll_up_interval=10, flush_in_thread=False) reporter = dog.reporter = MemoryReporter() dog.distribution('test.dist.1', 20, 100.0) dog.distribution('test.dist.1', 22, 105.0) dog.distribution('test.dist.2', 30, 115.0) dog.distribution('test.dist.3', 30, 125.0) dog.flush(120.0) # Assert they've been properly flushed. dists = self.sort_metrics(reporter.distributions) nt.assert_equal(len(dists), 2) (first, second) = dists nt.assert_equal(first['metric'], 'test.dist.1') nt.assert_equal(first['points'][0][0], 100.0) nt.assert_equal(first['points'][0][1], [20, 22]) nt.assert_equal(second['metric'], 'test.dist.2') # Flush again and make sure we're progressing. reporter.distributions = [] dog.flush(130.0) nt.assert_equal(len(reporter.distributions), 1) # Finally, make sure we've flushed all metrics. reporter.distributions = [] dog.flush(150.0) nt.assert_equal(len(reporter.distributions), 0)