Fixed random failures in storage tests

A bug related to list order in samples or result resulted in tests
sometimes failing. This is due to python3 not ordering dict indexes.

Change-Id: I276a2e9c896d94eaabb9206bd0123c5704b72fcb
This commit is contained in:
Stéphane Albert
2015-12-03 11:53:47 +01:00
parent 272a9cb1cb
commit 77c4788975
2 changed files with 11 additions and 2 deletions

View File

@@ -18,6 +18,8 @@
import copy
import decimal
import six
from cloudkitty import utils as ck_utils
TENANT = 'f266f30b11f246b589fd266f85eeec39'
@@ -107,7 +109,8 @@ def split_storage_data(raw_data):
frame['period']['begin'] = ck_utils.ts2iso(frame['period']['begin'])
frame['period']['end'] = ck_utils.ts2iso(frame['period']['end'])
usage_buffer = frame.pop('usage')
for service, data in usage_buffer.items():
# Sort to have a consistent result as we are converting it to a list
for service, data in sorted(six.iteritems(usage_buffer)):
new_frame = copy.deepcopy(frame)
new_frame['usage'] = {service: data}
new_frame['usage'][service][0]['tenant_id'] = TENANT

View File

@@ -18,6 +18,7 @@
import copy
import mock
import six
import sqlalchemy
import testscenarios
@@ -118,7 +119,7 @@ class StorageTest(tests.TestCase):
def test_send_nodata_between_data(self):
working_data = copy.deepcopy(samples.RATED_DATA)
for period in working_data:
for service, data in sorted(period['usage'].items()):
for service, data in sorted(six.iteritems(period['usage'])):
sub_data = [{
'period': period['period'],
'usage': {
@@ -148,6 +149,11 @@ class StorageTest(tests.TestCase):
# We only stored the first timeframe, the second one is waiting for a
# commit or an append with the next timeframe.
del expected_data[2]
# NOTE(sheeprine): Quick and dirty sort (ensure result consistency,
# order is not significant to the test result)
if 'image' in stored_data[0]['usage']:
stored_data[0]['usage'], stored_data[1]['usage'] = (
stored_data[1]['usage'], stored_data[0]['usage'])
self.assertEqual(
expected_data,
stored_data)