mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge #18617: test: add factor option to adjust test timeouts
2742c34286test: add factor option to adjust test timeouts (Harris) Pull request description: This PR adds a new option **factor** that can be used to adjust timeouts in various functional tests. Several timeouts and functions from `authproxy`, `mininode`, `test_node` and `util` have been adapted to use this option. The factor-option definition is located in `test_framework.py`. Fixes https://github.com/bitcoin/bitcoin/issues/18266 Also Fixes https://github.com/bitcoin/bitcoin/issues/18834 ACKs for top commit: MarcoFalke: Thanks! ACK2742c34286Tree-SHA512: 6d8421933ba2ac1b7db00b70cf2bc242d9842c48121c11aadc30b0985c4a174c86a127d6402d0cd73b993559d60d4f747872d21f9510cf4806e008349780d3ef
This commit is contained in:
@@ -120,8 +120,9 @@ class P2PConnection(asyncio.Protocol):
|
||||
def is_connected(self):
|
||||
return self._transport is not None
|
||||
|
||||
def peer_connect(self, dstaddr, dstport, *, net):
|
||||
def peer_connect(self, dstaddr, dstport, *, net, factor):
|
||||
assert not self.is_connected
|
||||
self.factor = factor
|
||||
self.dstaddr = dstaddr
|
||||
self.dstport = dstport
|
||||
# The initial message to send after the connection was made:
|
||||
@@ -367,9 +368,12 @@ class P2PInterface(P2PConnection):
|
||||
|
||||
# Connection helper methods
|
||||
|
||||
def wait_until(self, test_function, timeout):
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock, factor=self.factor)
|
||||
|
||||
def wait_for_disconnect(self, timeout=60):
|
||||
test_function = lambda: not self.is_connected
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
# Message receiving helper methods
|
||||
|
||||
@@ -380,14 +384,14 @@ class P2PInterface(P2PConnection):
|
||||
return False
|
||||
return self.last_message['tx'].tx.rehash() == txid
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
def wait_for_block(self, blockhash, timeout=60):
|
||||
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)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
def wait_for_header(self, blockhash, timeout=60):
|
||||
def test_function():
|
||||
@@ -397,7 +401,7 @@ class P2PInterface(P2PConnection):
|
||||
return False
|
||||
return last_headers.headers[0].rehash() == int(blockhash, 16)
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
def wait_for_merkleblock(self, blockhash, timeout=60):
|
||||
def test_function():
|
||||
@@ -407,7 +411,7 @@ class P2PInterface(P2PConnection):
|
||||
return False
|
||||
return last_filtered_block.merkleblock.header.rehash() == int(blockhash, 16)
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
def wait_for_getdata(self, hash_list, timeout=60):
|
||||
"""Waits for a getdata message.
|
||||
@@ -421,7 +425,7 @@ class P2PInterface(P2PConnection):
|
||||
return False
|
||||
return [x.hash for x in last_data.inv] == hash_list
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
def wait_for_getheaders(self, timeout=60):
|
||||
"""Waits for a getheaders message.
|
||||
@@ -435,7 +439,7 @@ class P2PInterface(P2PConnection):
|
||||
assert self.is_connected
|
||||
return self.last_message.get("getheaders")
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
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."""
|
||||
@@ -448,13 +452,13 @@ class P2PInterface(P2PConnection):
|
||||
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)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
def wait_for_verack(self, timeout=60):
|
||||
def test_function():
|
||||
return self.message_count["verack"]
|
||||
|
||||
wait_until(test_function, timeout=timeout, lock=mininode_lock)
|
||||
self.wait_until(test_function, timeout=timeout)
|
||||
|
||||
# Message sending helper functions
|
||||
|
||||
@@ -470,7 +474,7 @@ class P2PInterface(P2PConnection):
|
||||
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.wait_until(test_function, timeout=timeout)
|
||||
self.ping_counter += 1
|
||||
|
||||
|
||||
@@ -586,7 +590,7 @@ class P2PDataStore(P2PInterface):
|
||||
self.send_message(msg_block(block=b))
|
||||
else:
|
||||
self.send_message(msg_headers([CBlockHeader(block) for block in blocks]))
|
||||
wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock)
|
||||
self.wait_until(lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout)
|
||||
|
||||
if expect_disconnect:
|
||||
self.wait_for_disconnect(timeout=timeout)
|
||||
@@ -594,7 +598,7 @@ class P2PDataStore(P2PInterface):
|
||||
self.sync_with_ping(timeout=timeout)
|
||||
|
||||
if success:
|
||||
wait_until(lambda: node.getbestblockhash() == blocks[-1].hash, timeout=timeout)
|
||||
self.wait_until(lambda: node.getbestblockhash() == blocks[-1].hash, timeout=timeout)
|
||||
else:
|
||||
assert node.getbestblockhash() != blocks[-1].hash
|
||||
|
||||
|
||||
Reference in New Issue
Block a user