From 03ab144b8fe72381c4ad1f8e04748d2107d6eab7 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Wed, 28 Apr 2021 08:14:22 +0200 Subject: [PATCH] merge bitcoin#21785: Fix intermittent issue in p2p_addr_relay.py --- test/functional/p2p_addr_relay.py | 6 ++---- test/functional/p2p_blocksonly.py | 6 +----- test/functional/p2p_filter.py | 3 +-- test/functional/test_framework/p2p.py | 10 +++++++++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py index 53f5b5da13..f9c727d607 100755 --- a/test/functional/p2p_addr_relay.py +++ b/test/functional/p2p_addr_relay.py @@ -78,7 +78,7 @@ class AddrTest(BitcoinTestFramework): # pop m_next_addr_send timer self.bump_mocktime(5 * 60) for peer in receivers: - peer.sync_with_ping() + peer.sync_send_with_ping() def oversized_addr_test(self): self.log.info('Send an addr message that is too large') @@ -197,9 +197,7 @@ class AddrTest(BitcoinTestFramework): self.log.info('Check that we relay address messages') addr_source = self.nodes[0].add_p2p_connection(P2PInterface()) msg = self.setup_addr_msg(2) - addr_source.send_and_ping(msg) - self.bump_mocktime(5 * 60) - full_outbound_peer.sync_with_ping() + self.send_addr_msg(addr_source, msg, [full_outbound_peer]) assert_equal(full_outbound_peer.num_ipv4_received, 2) self.nodes[0].disconnect_p2ps() diff --git a/test/functional/p2p_blocksonly.py b/test/functional/p2p_blocksonly.py index 5f25edf424..f40d406fa2 100755 --- a/test/functional/p2p_blocksonly.py +++ b/test/functional/p2p_blocksonly.py @@ -90,11 +90,7 @@ class P2PBlocksOnly(BitcoinTestFramework): # Bump time forward to ensure nNextInvSend timer pops self.nodes[0].setmocktime(int(time.time()) + 60) - # Calling sync_with_ping twice requires that the node calls - # `ProcessMessage` twice, and thus ensures `SendMessages` must have - # been called at least once - conn.sync_with_ping() - conn.sync_with_ping() + conn.sync_send_with_ping() assert(int(txid, 16) not in conn.get_invs()) def check_p2p_tx_violation(self, index=1): diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py index 458e5235b6..4d4b693916 100755 --- a/test/functional/p2p_filter.py +++ b/test/functional/p2p_filter.py @@ -168,8 +168,7 @@ class FilterTest(BitcoinTestFramework): filter_peer.merkleblock_received = False filter_peer.tx_received = False self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 90) - filter_peer.sync_with_ping() - filter_peer.sync_with_ping() + filter_peer.sync_send_with_ping() assert not filter_peer.merkleblock_received assert not filter_peer.tx_received diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 103ea0420c..4e94149a48 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -577,8 +577,16 @@ class P2PInterface(P2PConnection): self.send_message(message) self.sync_with_ping(timeout=timeout) - # Sync up with the node + def sync_send_with_ping(self, timeout=60): + """Ensure SendMessages is called on this connection""" + # Calling sync_with_ping twice requires that the node calls + # `ProcessMessage` twice, and thus ensures `SendMessages` must have + # been called at least once + self.sync_with_ping() + self.sync_with_ping() + def sync_with_ping(self, timeout=60): + """Ensure ProcessMessages is called on this connection""" self.send_message(msg_ping(nonce=self.ping_counter)) def test_function():