account: Use Timestamps better in test_backend unit tests
Change-Id: I0b0fadce9e1231a45b10177d7d3e2c6bcde06a3d Signed-off-by: Matthew Oliver <matt@oliver.net.au>
This commit is contained in:
committed by
Alistair Coles
parent
48937cd183
commit
760829a75a
@@ -420,17 +420,18 @@ class TestAccountBroker(test_db.TestDbBase):
|
|||||||
def test_get_info(self):
|
def test_get_info(self):
|
||||||
# Test AccountBroker.get_info
|
# Test AccountBroker.get_info
|
||||||
broker = AccountBroker(self.get_db_path(), account='test1')
|
broker = AccountBroker(self.get_db_path(), account='test1')
|
||||||
broker.initialize(Timestamp('1').internal)
|
put_ts = next(self.ts)
|
||||||
|
broker.initialize(put_ts.internal)
|
||||||
|
|
||||||
info = broker.get_info()
|
info = broker.get_info()
|
||||||
self.assertEqual(info['account'], 'test1')
|
self.assertEqual(info['account'], 'test1')
|
||||||
self.assertEqual(info['hash'], '00000000000000000000000000000000')
|
self.assertEqual(info['hash'], '00000000000000000000000000000000')
|
||||||
self.assertEqual(info['put_timestamp'], Timestamp(1).internal)
|
self.assertEqual(info['put_timestamp'], put_ts.internal)
|
||||||
self.assertEqual(info['delete_timestamp'], '0')
|
self.assertEqual(info['delete_timestamp'], '0')
|
||||||
if self.__class__ == TestAccountBrokerBeforeMetadata:
|
if self.__class__ == TestAccountBrokerBeforeMetadata:
|
||||||
self.assertEqual(info['status_changed_at'], '0')
|
self.assertEqual(info['status_changed_at'], '0')
|
||||||
else:
|
else:
|
||||||
self.assertEqual(info['status_changed_at'], Timestamp(1).internal)
|
self.assertEqual(info['status_changed_at'], put_ts.internal)
|
||||||
|
|
||||||
info = broker.get_info()
|
info = broker.get_info()
|
||||||
self.assertEqual(info['container_count'], 0)
|
self.assertEqual(info['container_count'], 0)
|
||||||
@@ -597,20 +598,21 @@ class TestAccountBroker(test_db.TestDbBase):
|
|||||||
def test_list_objects_iter_order_and_reverse(self):
|
def test_list_objects_iter_order_and_reverse(self):
|
||||||
# Test ContainerBroker.list_objects_iter
|
# Test ContainerBroker.list_objects_iter
|
||||||
broker = AccountBroker(self.get_db_path(), account='a')
|
broker = AccountBroker(self.get_db_path(), account='a')
|
||||||
broker.initialize(Timestamp('1').internal, 0)
|
put_ts = next(self.ts)
|
||||||
|
broker.initialize(put_ts.internal, 0)
|
||||||
|
|
||||||
broker.put_container(
|
broker.put_container(
|
||||||
'c1', Timestamp(0).internal, 0, 0, 0, POLICIES.default.idx)
|
'c1', next(self.ts).internal, 0, 0, 0, POLICIES.default.idx)
|
||||||
broker.put_container(
|
broker.put_container(
|
||||||
'c10', Timestamp(0).internal, 0, 0, 0, POLICIES.default.idx)
|
'c10', next(self.ts).internal, 0, 0, 0, POLICIES.default.idx)
|
||||||
broker.put_container(
|
broker.put_container(
|
||||||
'C1', Timestamp(0).internal, 0, 0, 0, POLICIES.default.idx)
|
'C1', next(self.ts).internal, 0, 0, 0, POLICIES.default.idx)
|
||||||
broker.put_container(
|
broker.put_container(
|
||||||
'c2', Timestamp(0).internal, 0, 0, 0, POLICIES.default.idx)
|
'c2', next(self.ts).internal, 0, 0, 0, POLICIES.default.idx)
|
||||||
broker.put_container(
|
broker.put_container(
|
||||||
'c3', Timestamp(0).internal, 0, 0, 0, POLICIES.default.idx)
|
'c3', next(self.ts).internal, 0, 0, 0, POLICIES.default.idx)
|
||||||
broker.put_container(
|
broker.put_container(
|
||||||
'C4', Timestamp(0).internal, 0, 0, 0, POLICIES.default.idx)
|
'C4', next(self.ts).internal, 0, 0, 0, POLICIES.default.idx)
|
||||||
|
|
||||||
listing = broker.list_containers_iter(100, None, None, '', '',
|
listing = broker.list_containers_iter(100, None, None, '', '',
|
||||||
reverse=False)
|
reverse=False)
|
||||||
@@ -831,27 +833,30 @@ class TestAccountBroker(test_db.TestDbBase):
|
|||||||
|
|
||||||
def test_chexor(self):
|
def test_chexor(self):
|
||||||
broker = AccountBroker(self.get_db_path(), account='a')
|
broker = AccountBroker(self.get_db_path(), account='a')
|
||||||
broker.initialize(Timestamp('1').internal)
|
put_ts = next(self.ts)
|
||||||
broker.put_container('a', Timestamp(1).internal,
|
delete_ts = Timestamp(0)
|
||||||
Timestamp(0).internal, 0, 0,
|
timestamps = [next(self.ts) for _ in range(3)]
|
||||||
|
broker.initialize(put_ts.internal)
|
||||||
|
broker.put_container('a', timestamps[0].internal,
|
||||||
|
delete_ts.internal, 0, 0,
|
||||||
POLICIES.default.idx)
|
POLICIES.default.idx)
|
||||||
broker.put_container('b', Timestamp(2).internal,
|
broker.put_container('b', timestamps[1].internal,
|
||||||
Timestamp(0).internal, 0, 0,
|
delete_ts.internal, 0, 0,
|
||||||
POLICIES.default.idx)
|
POLICIES.default.idx)
|
||||||
text = '%s-%s' % ('a', "%s-%s-%s-%s" % (
|
text = '%s-%s' % ('a', "%s-%s-%s-%s" % (
|
||||||
Timestamp(1).internal, Timestamp(0).internal, 0, 0))
|
timestamps[0].internal, delete_ts.internal, 0, 0))
|
||||||
hasha = md5(text.encode('ascii'), usedforsecurity=False).digest()
|
hasha = md5(text.encode('ascii'), usedforsecurity=False).digest()
|
||||||
text = '%s-%s' % ('b', "%s-%s-%s-%s" % (
|
text = '%s-%s' % ('b', "%s-%s-%s-%s" % (
|
||||||
Timestamp(2).internal, Timestamp(0).internal, 0, 0))
|
timestamps[1].internal, delete_ts.internal, 0, 0))
|
||||||
hashb = md5(text.encode('ascii'), usedforsecurity=False).digest()
|
hashb = md5(text.encode('ascii'), usedforsecurity=False).digest()
|
||||||
hashc = ''.join(('%02x' % (a ^ b)
|
hashc = ''.join(('%02x' % (a ^ b)
|
||||||
for a, b in zip(hasha, hashb)))
|
for a, b in zip(hasha, hashb)))
|
||||||
self.assertEqual(broker.get_info()['hash'], hashc)
|
self.assertEqual(broker.get_info()['hash'], hashc)
|
||||||
broker.put_container('b', Timestamp(3).internal,
|
broker.put_container('b', timestamps[2].internal,
|
||||||
Timestamp(0).internal, 0, 0,
|
delete_ts.internal, 0, 0,
|
||||||
POLICIES.default.idx)
|
POLICIES.default.idx)
|
||||||
text = '%s-%s' % ('b', "%s-%s-%s-%s" % (
|
text = '%s-%s' % ('b', "%s-%s-%s-%s" % (
|
||||||
Timestamp(3).internal, Timestamp(0).internal, 0, 0))
|
timestamps[2].internal, delete_ts.internal, 0, 0))
|
||||||
hashb = md5(text.encode('ascii'), usedforsecurity=False).digest()
|
hashb = md5(text.encode('ascii'), usedforsecurity=False).digest()
|
||||||
hashc = ''.join(('%02x' % (a ^ b)
|
hashc = ''.join(('%02x' % (a ^ b)
|
||||||
for a, b in zip(hasha, hashb)))
|
for a, b in zip(hasha, hashb)))
|
||||||
@@ -1889,11 +1894,13 @@ class TestAccountBrokerBeforePerPolicyContainerTrack(
|
|||||||
|
|
||||||
def test_policy_table_cont_count_update_get_stats(self):
|
def test_policy_table_cont_count_update_get_stats(self):
|
||||||
# add a few container entries
|
# add a few container entries
|
||||||
|
ts_zero = Timestamp(0)
|
||||||
for policy in POLICIES:
|
for policy in POLICIES:
|
||||||
for i in range(0, policy.idx + 1):
|
for i in range(0, policy.idx + 1):
|
||||||
container_name = 'c%s_0' % policy.idx
|
container_name = 'c%s_0' % policy.idx
|
||||||
self.broker.put_container('c%s_%s' % (policy.idx, i),
|
self.broker.put_container('c%s_%s' % (policy.idx, i),
|
||||||
0, 0, 0, 0, policy.idx)
|
ts_zero.internal, ts_zero.internal,
|
||||||
|
0, 0, policy.idx)
|
||||||
# _commit_puts_stale_ok() called by get_policy_stats()
|
# _commit_puts_stale_ok() called by get_policy_stats()
|
||||||
|
|
||||||
# calling get_policy_stats() with do_migrations will alter the table
|
# calling get_policy_stats() with do_migrations will alter the table
|
||||||
@@ -1928,7 +1935,9 @@ class TestAccountBrokerBeforePerPolicyContainerTrack(
|
|||||||
# now put them back and make sure things are still cool
|
# now put them back and make sure things are still cool
|
||||||
for policy in POLICIES:
|
for policy in POLICIES:
|
||||||
container_name = 'c%s_0' % policy.idx
|
container_name = 'c%s_0' % policy.idx
|
||||||
self.broker.put_container(container_name, 0, 0, 0, 0, policy.idx)
|
self.broker.put_container(
|
||||||
|
container_name, ts_zero.internal, ts_zero.internal, 0, 0,
|
||||||
|
policy.idx)
|
||||||
# _commit_puts_stale_ok() called by get_policy_stats()
|
# _commit_puts_stale_ok() called by get_policy_stats()
|
||||||
|
|
||||||
# confirm stats reporting back correctly
|
# confirm stats reporting back correctly
|
||||||
|
|||||||
Reference in New Issue
Block a user