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
This commit is contained in:
Chris Dent 2014-07-12 16:19:58 +01:00
parent f7a0820f47
commit dac40f8297
1 changed files with 6 additions and 2 deletions

View File

@ -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):