Skip to content

Commit

Permalink
Merge bitcoin#21785: test: Fix intermittent issue in p2p_addr_relay.py
Browse files Browse the repository at this point in the history
faa51ef test: Fix intermittent issue in p2p_addr_relay.py (MarcoFalke)
fa37116 test: Use self.send_addr_msg (MarcoFalke)

Pull request description:

  Fixes https://github.com/bitcoin/bitcoin/pull/21707/files#r621048952

ACKs for top commit:
  mzumsande:
    ACK faa51ef
  amitiuttarwar:
    ACK faa51ef

Tree-SHA512: b1fbc1a4a13b020890b465083a82762981de17dd710388c651353aefc28dee23d39803c2a1dadbf88287e92598901afcb01b488115b0fecd746ab6d73775415b
  • Loading branch information
fanquake committed Apr 29, 2021
2 parents 2cbb4ab + faa51ef commit 7f37a1d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
7 changes: 2 additions & 5 deletions test/functional/p2p_addr_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def send_addr_msg(self, source, msg, receivers):
self.mocktime += 5 * 60
self.nodes[0].setmocktime(self.mocktime)
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')
Expand Down Expand Up @@ -203,10 +203,7 @@ def blocksonly_mode_tests(self):
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.mocktime += 5 * 60
self.nodes[0].setmocktime(self.mocktime)
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()
Expand Down
6 changes: 1 addition & 5 deletions test/functional/p2p_blocksonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ def blocks_relay_conn_tests(self):
# 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):
Expand Down
3 changes: 1 addition & 2 deletions test/functional/p2p_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ def test_filter(self, filter_peer):
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

Expand Down
10 changes: 9 additions & 1 deletion test/functional/test_framework/p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,16 @@ def send_and_ping(self, message, timeout=60):
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():
Expand Down

0 comments on commit 7f37a1d

Please sign in to comment.