Commit 00ea89c3 authored by Julien Muchembled's avatar Julien Muchembled

qa: do more checks on the partition table in testReplicationBlockedByUnfinished

parent d3cb8888
...@@ -258,30 +258,34 @@ class PartitionTable(object): ...@@ -258,30 +258,34 @@ class PartitionTable(object):
partition on the line (here, line length is 11 to keep the docstring partition on the line (here, line length is 11 to keep the docstring
width under 80 column). width under 80 column).
""" """
node_list = sorted(self.count_dict)
result = ['pt: node %u: %s, %s' % (i, uuid_str(node.getUUID()), result = ['pt: node %u: %s, %s' % (i, uuid_str(node.getUUID()),
protocol.node_state_prefix_dict[node.getState()]) protocol.node_state_prefix_dict[node.getState()])
for i, node in enumerate(node_list)] for i, node in enumerate(sorted(self.count_dict))]
append = result.append append = result.append
line = [] line = []
max_line_len = 20 # XXX: hardcoded number of partitions per line max_line_len = 20 # XXX: hardcoded number of partitions per line
cell_state_dict = protocol.cell_state_prefix_dict
prefix = 0 prefix = 0
prefix_len = int(math.ceil(math.log10(self.np))) prefix_len = int(math.ceil(math.log10(self.np)))
for offset, row in enumerate(self.partition_list): for offset, row in enumerate(self.formatRows()):
if len(line) == max_line_len: if len(line) == max_line_len:
append('pt: %0*u: %s' % (prefix_len, prefix, '|'.join(line))) append('pt: %0*u: %s' % (prefix_len, prefix, '|'.join(line)))
line = [] line = []
prefix = offset prefix = offset
line.append(row)
if line:
append('pt: %0*u: %s' % (prefix_len, prefix, '|'.join(line)))
return result
def formatRows(self):
node_list = sorted(self.count_dict)
cell_state_dict = protocol.cell_state_prefix_dict
for row in self.partition_list:
if row is None: if row is None:
line.append('X' * len(node_list)) yield 'X' * len(node_list)
else: else:
cell_dict = {x.getNode(): cell_state_dict[x.getState()] cell_dict = {x.getNode(): cell_state_dict[x.getState()]
for x in row} for x in row}
line.append(''.join(cell_dict.get(x, '.') for x in node_list)) yield ''.join(cell_dict.get(x, '.') for x in node_list)
if line:
append('pt: %0*u: %s' % (prefix_len, prefix, '|'.join(line)))
return result
def operational(self): def operational(self):
if not self.filled(): if not self.filled():
......
...@@ -929,6 +929,9 @@ class NEOThreadedTest(NeoTestBase): ...@@ -929,6 +929,9 @@ class NEOThreadedTest(NeoTestBase):
with Patch(client, _getFinalTID=lambda *_: None): with Patch(client, _getFinalTID=lambda *_: None):
self.assertRaises(ConnectionClosed, txn.commit) self.assertRaises(ConnectionClosed, txn.commit)
def assertPartitionTable(self, cluster, stats):
self.assertEqual(stats, '|'.join(cluster.admin.pt.formatRows()))
def predictable_random(seed=None): def predictable_random(seed=None):
# Because we have 2 running threads when client works, we can't # Because we have 2 running threads when client works, we can't
......
...@@ -502,6 +502,7 @@ class ReplicationTests(NEOThreadedTest): ...@@ -502,6 +502,7 @@ class ReplicationTests(NEOThreadedTest):
storage = cluster.getZODBStorage() storage = cluster.getZODBStorage()
oid = storage.new_oid() oid = storage.new_oid()
tid = None tid = None
expected = 'UO'
for n in 1, 0: for n in 1, 0:
# On first iteration, the transaction will block replication # On first iteration, the transaction will block replication
# until tpc_finish. # until tpc_finish.
...@@ -517,12 +518,13 @@ class ReplicationTests(NEOThreadedTest): ...@@ -517,12 +518,13 @@ class ReplicationTests(NEOThreadedTest):
cluster.enableStorageList((s1,)) cluster.enableStorageList((s1,))
cluster.neoctl.tweakPartitionTable() cluster.neoctl.tweakPartitionTable()
self.tic() self.tic()
self.assertEqual(n, len(cluster.getOutdatedCells())) self.assertPartitionTable(cluster, expected)
storage.tpc_vote(txn) storage.tpc_vote(txn)
self.assertEqual(n, len(cluster.getOutdatedCells())) self.assertPartitionTable(cluster, expected)
tid = storage.tpc_finish(txn) tid = storage.tpc_finish(txn)
self.tic() # replication resumes and ends self.tic() # replication resumes and ends
self.assertFalse(cluster.getOutdatedCells()) expected = 'UU'
self.assertPartitionTable(cluster, expected)
self.assertEqual(cluster.neoctl.getClusterState(), self.assertEqual(cluster.neoctl.getClusterState(),
ClusterStates.RUNNING) ClusterStates.RUNNING)
finally: finally:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment