aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/test_framework
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2016-11-10 11:22:26 +0100
committerMarcoFalke <falke.marco@gmail.com>2016-11-10 11:23:40 +0100
commite5364991daecb73aca3bb5ac37f2619d7a89211b (patch)
tree9810a9835220daff026db2e1930882e41b0c12bf /qa/rpc-tests/test_framework
parent4a2b170c075ce703cbdc82519a48016a9ee3f99c (diff)
parentfa97ccb06d59f56d215004ee1aa7dd786fae9d6d (diff)
Merge #9097: [qa] Rework sync_* and preciousblock.py
fa97ccb [qa] util: Rework sync_*() (MarcoFalke) fac1141 [qa] preciousblock: Use assert_equal and BitcoinTestFramework.__init__ (MarcoFalke)
Diffstat (limited to 'qa/rpc-tests/test_framework')
-rw-r--r--qa/rpc-tests/test_framework/util.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py
index c0c2b3a6ef..b5ef0689b4 100644
--- a/qa/rpc-tests/test_framework/util.py
+++ b/qa/rpc-tests/test_framework/util.py
@@ -121,33 +121,35 @@ def hex_str_to_bytes(hex_str):
def str_to_b64str(string):
return b64encode(string.encode('utf-8')).decode('ascii')
-def sync_blocks(rpc_connections, wait=1, timeout=60):
+def sync_blocks(rpc_connections, *, wait=1, timeout=60):
"""
Wait until everybody has the same tip
"""
maxheight = 0
while timeout > 0:
- tips = [ x.waitforblockheight(maxheight, int(wait * 1000)) for x in rpc_connections ]
- heights = [ x["height"] for x in tips ]
- if tips == [ tips[0] ]*len(tips):
- return True
- if heights == [ heights[0] ]*len(heights): #heights are the same but hashes are not
- raise AssertionError("Block sync failed")
+ tips = [r.waitforblockheight(maxheight, int(wait * 1000)) for r in rpc_connections]
+ heights = [t["height"] for t in tips]
+ if tips == [tips[0]] * len(tips):
+ return
+ if heights == [heights[0]] * len(heights):
+ raise AssertionError("Block sync failed: (Hashes don't match)")
timeout -= wait
maxheight = max(heights)
- raise AssertionError("Block sync failed")
+ raise AssertionError("Block sync failed with heights: {}".format(heights))
-def sync_chain(rpc_connections, wait=1):
+def sync_chain(rpc_connections, *, wait=1, timeout=60):
"""
Wait until everybody has the same best block
"""
- while True:
- counts = [ x.getbestblockhash() for x in rpc_connections ]
- if counts == [ counts[0] ]*len(counts):
- break
+ while timeout > 0:
+ best_hash = [x.getbestblockhash() for x in rpc_connections]
+ if best_hash == [best_hash[0]]*len(best_hash):
+ return
time.sleep(wait)
+ timeout -= wait
+ raise AssertionError("Chain sync failed: Best block hashes don't match")
-def sync_mempools(rpc_connections, wait=1, timeout=60):
+def sync_mempools(rpc_connections, *, wait=1, timeout=60):
"""
Wait until everybody has the same transactions in their memory
pools
@@ -159,7 +161,7 @@ def sync_mempools(rpc_connections, wait=1, timeout=60):
if set(rpc_connections[i].getrawmempool()) == pool:
num_match = num_match+1
if num_match == len(rpc_connections):
- return True
+ return
time.sleep(wait)
timeout -= wait
raise AssertionError("Mempool sync failed")