Skip to content

Commit b422913

Browse files
author
MarcoFalke
committed
Merge #9136: sync_blocks cleanup
7943b13 [qa] Avoid 2 list comprehensions in sync_blocks (Russell Yanofsky) 05e57cc [qa] Fix sync_blocks timeout argument (Russell Yanofsky) fd6bb70 [qa] Improve sync_blocks error messages. (Russell Yanofsky)
2 parents 924745d + 7943b13 commit b422913

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

qa/rpc-tests/test_framework/util.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,26 @@ def str_to_b64str(string):
123123

124124
def sync_blocks(rpc_connections, *, wait=1, timeout=60):
125125
"""
126-
Wait until everybody has the same tip
126+
Wait until everybody has the same tip.
127+
128+
sync_blocks needs to be called with an rpc_connections set that has least
129+
one node already synced to the latest, stable tip, otherwise there's a
130+
chance it might return before all nodes are stably synced.
127131
"""
128132
maxheight = 0
129-
while timeout > 0:
133+
start_time = cur_time = time.time()
134+
while cur_time <= start_time + timeout:
130135
tips = [r.waitforblockheight(maxheight, int(wait * 1000)) for r in rpc_connections]
131136
heights = [t["height"] for t in tips]
132-
if tips == [tips[0]] * len(tips):
137+
if all(t == tips[0] for t in tips):
133138
return
134-
if heights == [heights[0]] * len(heights):
135-
raise AssertionError("Block sync failed: (Hashes don't match)")
136-
timeout -= wait
139+
if all(h == heights[0] for h in heights):
140+
raise AssertionError("Block sync failed, mismatched block hashes:{}".format(
141+
"".join("\n {!r}".format(tip) for tip in tips)))
137142
maxheight = max(heights)
138-
raise AssertionError("Block sync failed with heights: {}".format(heights))
143+
cur_time = time.time()
144+
raise AssertionError("Block sync to height {} timed out:{}".format(
145+
maxheight, "".join("\n {!r}".format(tip) for tip in tips)))
139146

140147
def sync_chain(rpc_connections, *, wait=1, timeout=60):
141148
"""

0 commit comments

Comments
 (0)