mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-30 18:51:15 +02:00
p2p: Use mocktime for ping timeout
This commit is contained in:
@ -30,11 +30,16 @@ class NodeNoPong(P2PInterface):
|
||||
pass
|
||||
|
||||
|
||||
TIMEOUT_INTERVAL = 20 * 60
|
||||
|
||||
|
||||
class PingPongTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [['-peertimeout=3']]
|
||||
# Set the peer connection timeout low. It does not matter for this
|
||||
# test, as long as it is less than TIMEOUT_INTERVAL.
|
||||
self.extra_args = [['-peertimeout=1']]
|
||||
|
||||
def check_peer_info(self, *, pingtime, minping, pingwait):
|
||||
stats = self.nodes[0].getpeerinfo()[0]
|
||||
@ -110,8 +115,11 @@ class PingPongTest(BitcoinTestFramework):
|
||||
self.nodes[0].ping()
|
||||
no_pong_node.wait_until(lambda: 'ping' in no_pong_node.last_message)
|
||||
with self.nodes[0].assert_debug_log(['ping timeout: 1201.000000s']):
|
||||
self.mock_forward(20 * 60 + 1)
|
||||
time.sleep(4) # peertimeout + 1
|
||||
self.mock_forward(TIMEOUT_INTERVAL // 2)
|
||||
# Check that sending a ping does not prevent the disconnect
|
||||
no_pong_node.sync_with_ping()
|
||||
self.mock_forward(TIMEOUT_INTERVAL // 2 + 1)
|
||||
no_pong_node.wait_for_disconnect()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user