0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

test: Fix intermittent issue in p2p_addr_relay.py

This commit is contained in:
MarcoFalke 2021-04-27 13:32:23 +02:00
parent fa37116c82
commit faa51ef4d3
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
4 changed files with 12 additions and 9 deletions

View file

@ -82,7 +82,7 @@ class AddrTest(BitcoinTestFramework):
self.mocktime += 5 * 60 self.mocktime += 5 * 60
self.nodes[0].setmocktime(self.mocktime) self.nodes[0].setmocktime(self.mocktime)
for peer in receivers: for peer in receivers:
peer.sync_with_ping() peer.sync_send_with_ping()
def oversized_addr_test(self): def oversized_addr_test(self):
self.log.info('Send an addr message that is too large') self.log.info('Send an addr message that is too large')

View file

@ -89,11 +89,7 @@ class P2PBlocksOnly(BitcoinTestFramework):
# Bump time forward to ensure nNextInvSend timer pops # Bump time forward to ensure nNextInvSend timer pops
self.nodes[0].setmocktime(int(time.time()) + 60) self.nodes[0].setmocktime(int(time.time()) + 60)
# Calling sync_with_ping twice requires that the node calls conn.sync_send_with_ping()
# `ProcessMessage` twice, and thus ensures `SendMessages` must have
# been called at least once
conn.sync_with_ping()
conn.sync_with_ping()
assert(int(txid, 16) not in conn.get_invs()) assert(int(txid, 16) not in conn.get_invs())
def check_p2p_tx_violation(self, index=1): def check_p2p_tx_violation(self, index=1):

View file

@ -174,8 +174,7 @@ class FilterTest(BitcoinTestFramework):
filter_peer.merkleblock_received = False filter_peer.merkleblock_received = False
filter_peer.tx_received = False filter_peer.tx_received = False
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 90) self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 90)
filter_peer.sync_with_ping() filter_peer.sync_send_with_ping()
filter_peer.sync_with_ping()
assert not filter_peer.merkleblock_received assert not filter_peer.merkleblock_received
assert not filter_peer.tx_received assert not filter_peer.tx_received

View file

@ -539,8 +539,16 @@ class P2PInterface(P2PConnection):
self.send_message(message) self.send_message(message)
self.sync_with_ping(timeout=timeout) 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): def sync_with_ping(self, timeout=60):
"""Ensure ProcessMessages is called on this connection"""
self.send_message(msg_ping(nonce=self.ping_counter)) self.send_message(msg_ping(nonce=self.ping_counter))
def test_function(): def test_function():