diff options
author | Cory Fields <cory-nospam-@coryfields.com> | 2016-09-01 21:55:21 -0400 |
---|---|---|
committer | Cory Fields <cory-nospam-@coryfields.com> | 2016-09-07 12:46:01 -0400 |
commit | d6a5dc4a2eaa0d7348804254ca09e75fc3a858ab (patch) | |
tree | dd60ab61035edb6e519f9f69b4d80d48de079ff2 /qa/rpc-tests | |
parent | 5b2ea29cf4fd298346437bb16a54407f8c1f9dca (diff) | |
download | bitcoin-d6a5dc4a2eaa0d7348804254ca09e75fc3a858ab.tar.xz |
add waitfornewblock/waitforblock/waitforblockheight rpcs and use them for tests
waitfornewblock waits until a new block is received, or the timeout expires, then
returns the current block height/hash.
waitforblock waits for a specific blockhash, or until the timeout expires, then
returns the current block height/hash. If the target blockhash is the current
tip, it will return immediately.
waitforblockheight waits until the tip has reached a certain height or higher,
then returns the current height and hash.
waitforblockheight is used to avoid polling in the rpc tests.
Diffstat (limited to 'qa/rpc-tests')
-rw-r--r-- | qa/rpc-tests/test_framework/util.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 190fa7f661..eee77f1a10 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -125,12 +125,16 @@ def sync_blocks(rpc_connections, wait=1, timeout=60): """ Wait until everybody has the same tip """ + maxheight = 0 while timeout > 0: - tips = [ x.getbestblockhash() for x in rpc_connections ] + 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 - time.sleep(wait) + if heights == [ heights[0] ]*len(heights): #heights are the same but hashes are not + raise AssertionError("Block sync failed") timeout -= wait + maxheight = max(heights) raise AssertionError("Block sync failed") def sync_mempools(rpc_connections, wait=1, timeout=60): |