mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Merge #8104: Tests: add timeout to sync_blocks() and sync_mempools()
e871f83
Tests: add timeout to sync_blocks() and sync_mempools() (Suhas Daftuar)
This commit is contained in:
parent
8d47ecb232
commit
0027292ac6
@ -131,30 +131,34 @@ def hex_str_to_bytes(hex_str):
|
|||||||
def str_to_b64str(string):
|
def str_to_b64str(string):
|
||||||
return b64encode(string.encode('utf-8')).decode('ascii')
|
return b64encode(string.encode('utf-8')).decode('ascii')
|
||||||
|
|
||||||
def sync_blocks(rpc_connections, wait=1):
|
def sync_blocks(rpc_connections, wait=1, timeout=60):
|
||||||
"""
|
"""
|
||||||
Wait until everybody has the same block count
|
Wait until everybody has the same tip
|
||||||
"""
|
"""
|
||||||
while True:
|
while timeout > 0:
|
||||||
counts = [ x.getblockcount() for x in rpc_connections ]
|
tips = [ x.getbestblockhash() for x in rpc_connections ]
|
||||||
if counts == [ counts[0] ]*len(counts):
|
if tips == [ tips[0] ]*len(tips):
|
||||||
break
|
return True
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
|
timeout -= wait
|
||||||
|
raise AssertionError("Block sync failed")
|
||||||
|
|
||||||
def sync_mempools(rpc_connections, wait=1):
|
def sync_mempools(rpc_connections, wait=1, timeout=60):
|
||||||
"""
|
"""
|
||||||
Wait until everybody has the same transactions in their memory
|
Wait until everybody has the same transactions in their memory
|
||||||
pools
|
pools
|
||||||
"""
|
"""
|
||||||
while True:
|
while timeout > 0:
|
||||||
pool = set(rpc_connections[0].getrawmempool())
|
pool = set(rpc_connections[0].getrawmempool())
|
||||||
num_match = 1
|
num_match = 1
|
||||||
for i in range(1, len(rpc_connections)):
|
for i in range(1, len(rpc_connections)):
|
||||||
if set(rpc_connections[i].getrawmempool()) == pool:
|
if set(rpc_connections[i].getrawmempool()) == pool:
|
||||||
num_match = num_match+1
|
num_match = num_match+1
|
||||||
if num_match == len(rpc_connections):
|
if num_match == len(rpc_connections):
|
||||||
break
|
return True
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
|
timeout -= wait
|
||||||
|
raise AssertionError("Mempool sync failed")
|
||||||
|
|
||||||
def sync_masternodes(rpc_connections):
|
def sync_masternodes(rpc_connections):
|
||||||
for node in rpc_connections:
|
for node in rpc_connections:
|
||||||
|
Loading…
Reference in New Issue
Block a user