Skip to content

Commit 3ded43e

Browse files
fanquakevijaydasmp
authored andcommitted
Merge 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#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
1 parent 17ef2a4 commit 3ded43e

7 files changed

Lines changed: 11 additions & 15 deletions

File tree

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
@@ -104,7 +104,7 @@ def blocks_relay_conn_tests(self):
104104
# Bump time forward to ensure m_next_inv_send_time timer pops
105105
self.nodes[0].setmocktime(int(time.time()) + 60)
106106

107-
conn.sync_send_with_ping()
107+
conn.sync_with_ping()
108108
assert int(txid, 16) not in conn.get_invs()
109109

110110
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
@@ -93,11 +93,11 @@ def run_test(self):
9393
block1 = self.build_block_on_tip()
9494

9595
p2p_conn_blocksonly.send_message(msg_headers(headers=[CBlockHeader(block1)]))
96-
p2p_conn_blocksonly.sync_send_with_ping()
96+
p2p_conn_blocksonly.sync_with_ping()
9797
assert_equal(p2p_conn_blocksonly.last_message['getdata'].inv, [CInv(MSG_BLOCK, block1.sha256)])
9898

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

103103
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
@@ -161,7 +161,7 @@ def total_bytes_recv_for_blocks(self):
161161
def all_sync_send_with_ping(self, peers):
162162
for p in peers:
163163
if p.is_connected:
164-
p.sync_send_with_ping()
164+
p.sync_with_ping()
165165

166166
def is_block_requested(self, peers, hash):
167167
for p in peers:

test/functional/p2p_ibd_txrelay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def run_test(self):
4646
peer_inver.send_and_ping(msg_inv([CInv(t=MSG_TX, h=txid)]))
4747
# The node should not send a getdata, but if it did, it would first delay 2 seconds
4848
self.nodes[0].setmocktime(int(time.time() + NONPREF_PEER_TX_DELAY))
49-
peer_inver.sync_send_with_ping()
49+
peer_inver.sync_with_ping()
5050
with p2p_lock:
5151
assert txid not in peer_inver.getdata_requests
5252
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
@@ -751,16 +751,12 @@ def send_and_ping(self, message, *, timeout=60):
751751
self.send_message(message)
752752
self.sync_with_ping(timeout=timeout)
753753

754-
def sync_send_with_ping(self, *, timeout=60):
755-
"""Ensure SendMessages is called on this connection"""
756-
# Calling sync_with_ping twice requires that the node calls
754+
def sync_with_ping(self, *, timeout=60):
755+
"""Ensure ProcessMessages and SendMessages is called on this connection"""
756+
# Sending two pings back-to-back, requires that the node calls
757757
# `ProcessMessage` twice, and thus ensures `SendMessages` must have
758758
# been called at least once
759-
self.sync_with_ping()
760-
self.sync_with_ping()
761-
762-
def sync_with_ping(self, *, timeout=60):
763-
"""Ensure ProcessMessages is called on this connection"""
759+
self.send_message(msg_ping(nonce=0))
764760
self.send_message(msg_ping(nonce=self.ping_counter))
765761

766762
def test_function():

0 commit comments

Comments
 (0)