def test_collate_multiple_measurements(self):
        builder = self._make_simple_rule_builder()
        output = {}
        measurements2xx = self._make_timer_measurements(status='2xx')
        measurements4xx = self._make_timer_measurements(status='4xx')
        measurements5xx = self._make_timer_measurements(status='5xx')
        measurements = [
            measurements2xx[0],
            measurements4xx[1],
            measurements5xx[0],
            measurements4xx[0],
            measurements2xx[1],
            measurements5xx[1],
        ]
        for measurement in measurements:
            builder._collate_metric_info(
                MetricInfo(measurement['values'][0],
                           sorted(measurement['tags'])), output)

        expect_values = [
            MetricInfo(
                {
                    't': self.TIMESTAMP,
                    'v': {
                        'count': 123,
                        'totalTime': 321
                    }
                }, self._determine_expected_tags(measurements2xx[0])),

            # different value, same time
            MetricInfo(
                {
                    't': self.TIMESTAMP,
                    'v': {
                        'count': 123 + 400,
                        'totalTime': 321 + 400
                    }
                }, self._determine_expected_tags(measurements4xx[0])),

            # different value, different time
            MetricInfo(
                {
                    't': self.TIMESTAMP + 500,
                    'v': {
                        'count': 123 + 500,
                        'totalTime': 321 + 500
                    }
                }, self._determine_expected_tags(measurements5xx[0]))
        ]

        for got in output.values():
            found = False
            for index, expect in enumerate(expect_values):
                if got == expect:
                    del expect_values[index]
                    found = True
                    break
            self.assertTrue(found, msg='Missing %r' % got)
        self.assertEquals([], expect_values)
  def test_collate_one_measurement(self):
    builder = self._make_simple_rule_builder()
    output = {}
    measurements = self._make_timer_measurements()
    for measurement in measurements:
      builder._collate_metric_info(
          MetricInfo(measurement['values'][0], sorted(measurement['tags'])),
          output)

    self.assertEquals(
        sorted([
            MetricInfo({'t': self.TIMESTAMP,
                        'v': {'count': 123, 'totalTime': 321}},
                       self._determine_expected_tags(measurements[0]))
        ]),
        sorted(output.values()))