Skip to content

Commit cf42182

Browse files
committed
Merge bitcoin/bitcoin#28409: test: Combine sync_send_with_ping and sync_with_ping
fae0b21 test: Combine sync_send_with_ping and sync_with_ping (MarcoFalke) Pull request description: This reduces bloat, complexity, and makes tests less fragile to intermittent failures, see bitcoin/bitcoin#27675 (comment). This should not cause any noticeable slowdown, or may even be faster, because active polling will be done at most once. ACKs for top commit: glozow: Concept ACK fae0b21 theStack: ACK fae0b21 🏓 Tree-SHA512: 6c543241a7b85458dc7ff6a6203316b80a6227d83d38427e74f53f4c666a882647a8a221e5259071ee7bb5dfd63476fb03c9b558a1ea546734b14728c3c619ba
2 parents 9d3b216 + fae0b21 commit cf42182

File tree

8 files changed

+12
-16
lines changed

8 files changed

+12
-16
lines changed

test/functional/p2p_addr_relay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def send_addr_msg(self, source, msg, receivers):
133133
self.mocktime += 10 * 60
134134
self.nodes[0].setmocktime(self.mocktime)
135135
for peer in receivers:
136-
peer.sync_send_with_ping()
136+
peer.sync_with_ping()
137137

138138
def oversized_addr_test(self):
139139
self.log.info('Send an addr message that is too large')

test/functional/p2p_addrfetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def run_test(self):
4848
self.assert_getpeerinfo(peer_ids=[peer_id])
4949

5050
self.log.info("Check that we send getaddr but don't try to sync headers with the addr-fetch peer")
51-
peer.sync_send_with_ping()
51+
peer.sync_with_ping()
5252
with p2p_lock:
5353
assert peer.message_count['getaddr'] == 1
5454
assert peer.message_count['getheaders'] == 0

test/functional/p2p_blocksonly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def blocks_relay_conn_tests(self):
101101
# Bump time forward to ensure m_next_inv_send_time timer pops
102102
self.nodes[0].setmocktime(int(time.time()) + 60)
103103

104-
conn.sync_send_with_ping()
104+
conn.sync_with_ping()
105105
assert int(txid, 16) not in conn.get_invs()
106106

107107
def check_p2p_inv_violation(self, peer):

test/functional/p2p_compactblocks_blocksonly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ def run_test(self):
9494
block1 = self.build_block_on_tip()
9595

9696
p2p_conn_blocksonly.send_message(msg_headers(headers=[CBlockHeader(block1)]))
97-
p2p_conn_blocksonly.sync_send_with_ping()
97+
p2p_conn_blocksonly.sync_with_ping()
9898
assert_equal(p2p_conn_blocksonly.last_message['getdata'].inv, [CInv(MSG_BLOCK | MSG_WITNESS_FLAG, block1.sha256)])
9999

100100
p2p_conn_high_bw.send_message(msg_headers(headers=[CBlockHeader(block1)]))
101-
p2p_conn_high_bw.sync_send_with_ping()
101+
p2p_conn_high_bw.sync_with_ping()
102102
assert_equal(p2p_conn_high_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.sha256)])
103103

104104
self.log.info("Test that getdata(CMPCT) is still sent on BIP152 low bandwidth connections"

test/functional/p2p_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_filter(self, filter_peer):
177177
filter_peer.merkleblock_received = False
178178
filter_peer.tx_received = False
179179
self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=7 * COIN)
180-
filter_peer.sync_send_with_ping()
180+
filter_peer.sync_with_ping()
181181
assert not filter_peer.merkleblock_received
182182
assert not filter_peer.tx_received
183183

test/functional/p2p_ibd_stalling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def total_bytes_recv_for_blocks(self):
151151
def all_sync_send_with_ping(self, peers):
152152
for p in peers:
153153
if p.is_connected:
154-
p.sync_send_with_ping()
154+
p.sync_with_ping()
155155

156156
def is_block_requested(self, peers, hash):
157157
for p in peers:

test/functional/p2p_ibd_txrelay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def run_test(self):
5353
peer_inver.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=txid)]))
5454
# The node should not send a getdata, but if it did, it would first delay 2 seconds
5555
self.nodes[0].setmocktime(int(time.time() + NONPREF_PEER_TX_DELAY))
56-
peer_inver.sync_send_with_ping()
56+
peer_inver.sync_with_ping()
5757
with p2p_lock:
5858
assert txid not in peer_inver.getdata_requests
5959
self.nodes[0].disconnect_p2ps()

test/functional/test_framework/p2p.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,12 @@ def send_and_ping(self, message, timeout=60):
558558
self.send_message(message)
559559
self.sync_with_ping(timeout=timeout)
560560

561-
def sync_send_with_ping(self, timeout=60):
562-
"""Ensure SendMessages is called on this connection"""
563-
# Calling sync_with_ping twice requires that the node calls
561+
def sync_with_ping(self, timeout=60):
562+
"""Ensure ProcessMessages and SendMessages is called on this connection"""
563+
# Sending two pings back-to-back, requires that the node calls
564564
# `ProcessMessage` twice, and thus ensures `SendMessages` must have
565565
# been called at least once
566-
self.sync_with_ping()
567-
self.sync_with_ping()
568-
569-
def sync_with_ping(self, timeout=60):
570-
"""Ensure ProcessMessages is called on this connection"""
566+
self.send_message(msg_ping(nonce=0))
571567
self.send_message(msg_ping(nonce=self.ping_counter))
572568

573569
def test_function():

0 commit comments

Comments
 (0)