From dac40f8297d1f291419dfae17c79084a272a5c5e Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Sat, 12 Jul 2014 16:19:58 +0100 Subject: [PATCH] Fix incorrect use of timestamp in test The timestamp used has a very slim chance of being in a different second than actually desired which would tickle the bug. The bug itself is simply that the mapping between sample and timestamp was incorrect. To make sure that there isn't confusion over distinct timestamps, _make_timestamps has been changed so that if multiple timestamps are requested, each is a second after the previous. Change-Id: I22d999c506a30d4ca6b8dd7e9de501570257b99e Closes-bug: 1341142 --- ceilometer/tests/network/statistics/test_statistics.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ceilometer/tests/network/statistics/test_statistics.py b/ceilometer/tests/network/statistics/test_statistics.py index df258f1e8..b327bf2ec 100644 --- a/ceilometer/tests/network/statistics/test_statistics.py +++ b/ceilometer/tests/network/statistics/test_statistics.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import datetime + from ceilometer.network import statistics from ceilometer.network.statistics import driver from ceilometer.openstack.common import test @@ -91,7 +93,9 @@ class TestBaseGetSamples(test.BaseTestCase): return FakeDriver def _make_timestamps(self, count): - return [timeutils.isotime() for i in range(count)] + now = timeutils.utcnow() + return [timeutils.isotime(now + datetime.timedelta(seconds=i)) + for i in range(count)] def _get_samples(self, *resources): @@ -134,7 +138,7 @@ class TestBaseGetSamples(test.BaseTestCase): samples = self._get_samples('http://foo', 'http://bar') self.assertEqual(len(samples), 2) - self._assert_sample(samples[0], 1, 'a', {'spam': 'egg'}, times[2]) + self._assert_sample(samples[0], 1, 'a', {'spam': 'egg'}, times[0]) self._assert_sample(samples[1], 2, 'b', None, times[1]) def test_get_samples_two_driver_one_resource(self):