p2p: Use mocktime for ping timeout

This commit is contained in:
MarcoFalke
2021-10-07 13:22:51 +02:00
parent c0b6c96eee
commit fadf1186c8
6 changed files with 25 additions and 7 deletions

View File

@ -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__':