mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #16470: test: Fail early on disconnect in mininode.wait_for_*
fac2e6a6045e4ddd6b473f4f3ddbb69d9d6921f6 test: Fail early on disconnect in mininode.wait_for_* (MarcoFalke) Pull request description: The node might crash or disconnect when our mininode waits for data. Due to the crash, the data is guaranteed to never arrive and we can fail early with an assert ACKs for top commit: laanwj: ACK fac2e6a6045e4ddd6b473f4f3ddbb69d9d6921f6 Tree-SHA512: 32ca844eb66bd70ea49103d51c76b953242b1886e0834d96fca8840fc984ff40346d0a799adf8f76b03514a783cb9cec69d45e00bdd328c5192c31b5d8d17af2
This commit is contained in:
parent
3c6c78e256
commit
281e00f1f5
@ -422,6 +422,7 @@ class P2PInterface(P2PConnection):
|
||||
|
||||
def wait_for_tx(self, txid, timeout=60):
|
||||
def test_function():
|
||||
assert self.is_connected
|
||||
if not self.last_message.get('tx'):
|
||||
return False
|
||||
return self.last_message['tx'].tx.rehash() == txid
|
||||
@ -429,11 +430,15 @@ class P2PInterface(P2PConnection):
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
def wait_for_block(self, blockhash, timeout=60):
|
||||
test_function = lambda: self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
|
||||
def test_function():
|
||||
assert self.is_connected
|
||||
return self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
def wait_for_header(self, blockhash, timeout=60):
|
||||
def test_function():
|
||||
assert self.is_connected
|
||||
last_headers = self.last_message.get('headers')
|
||||
if not last_headers:
|
||||
return False
|
||||
@ -448,7 +453,11 @@ class P2PInterface(P2PConnection):
|
||||
value must be explicitly cleared before calling this method, or this will return
|
||||
immediately with success. TODO: change this method to take a hash value and only
|
||||
return true if the correct block/tx has been requested."""
|
||||
test_function = lambda: self.last_message.get("getdata")
|
||||
|
||||
def test_function():
|
||||
assert self.is_connected
|
||||
return self.last_message.get("getdata")
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
def wait_for_getheaders(self, timeout=60):
|
||||
@ -458,20 +467,30 @@ class P2PInterface(P2PConnection):
|
||||
value must be explicitly cleared before calling this method, or this will return
|
||||
immediately with success. TODO: change this method to take a hash value and only
|
||||
return true if the correct block header has been requested."""
|
||||
test_function = lambda: self.last_message.get("getheaders")
|
||||
|
||||
def test_function():
|
||||
assert self.is_connected
|
||||
return self.last_message.get("getheaders")
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
def wait_for_inv(self, expected_inv, timeout=60):
|
||||
"""Waits for an INV message and checks that the first inv object in the message was as expected."""
|
||||
if len(expected_inv) > 1:
|
||||
raise NotImplementedError("wait_for_inv() will only verify the first inv object")
|
||||
test_function = lambda: self.last_message.get("inv") and \
|
||||
|
||||
def test_function():
|
||||
assert self.is_connected
|
||||
return self.last_message.get("inv") and \
|
||||
self.last_message["inv"].inv[0].type == expected_inv[0].type and \
|
||||
self.last_message["inv"].inv[0].hash == expected_inv[0].hash
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
def wait_for_verack(self, timeout=60):
|
||||
test_function = lambda: self.message_count["verack"]
|
||||
def test_function():
|
||||
return self.message_count["verack"]
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
# Message sending helper functions
|
||||
@ -483,7 +502,11 @@ class P2PInterface(P2PConnection):
|
||||
# Sync up with the node
|
||||
def sync_with_ping(self, timeout=60):
|
||||
self.send_message(msg_ping(nonce=self.ping_counter))
|
||||
test_function = lambda: self.last_message.get("pong") and self.last_message["pong"].nonce == self.ping_counter
|
||||
|
||||
def test_function():
|
||||
assert self.is_connected
|
||||
return self.last_message.get("pong") and self.last_message["pong"].nonce == self.ping_counter
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
self.ping_counter += 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user