Skip to content

Commit 7eeae5c

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#26553: test: Fix intermittent failure in rpc_net.py
0f6cd72 test: Fix intermittent failure in rpc_net.py (Martin Zumsande) Pull request description: Fixes #26552. The problem was that calling `disconnect_p2ps` waits until `self.num_test_p2p_connections() == 0`. `num_test_p2p_connections()` checks the field `subver` in `getpeerinfo` to distinguish p2p nodes from full nodes. However, if we are dealing with a p2p connection that has never sent a version, the node has never received the special subversion and the wait is ineffective (we continue even though the disconnection is not yet completed). Fix this by not using `disconnect_p2ps`. ACKs for top commit: MarcoFalke: ACK 0f6cd72 Tree-SHA512: ebdc78498db6971ae2f9b494dc76b35de46155bf191ce82ee04162592d0d9ec1272901992406d530fa46fb52cd815c4b91350824578292df14986584bc60b90a
2 parents 1b68094 + 0f6cd72 commit 7eeae5c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

test/functional/rpc_net.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_getpeerinfo(self):
112112
no_version_peer_conntime = int(time.time())
113113
self.nodes[0].setmocktime(no_version_peer_conntime)
114114
with self.nodes[0].assert_debug_log([f"Added connection peer={no_version_peer_id}"]):
115-
self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
115+
no_version_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
116116
self.nodes[0].setmocktime(0)
117117
peer_info = self.nodes[0].getpeerinfo()[no_version_peer_id]
118118
peer_info.pop("addr")
@@ -153,7 +153,8 @@ def test_getpeerinfo(self):
153153
"version": 0,
154154
},
155155
)
156-
self.nodes[0].disconnect_p2ps()
156+
no_version_peer.peer_disconnect()
157+
self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 2)
157158

158159
def test_getnettotals(self):
159160
self.log.info("Test getnettotals")

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ def num_test_p2p_connections(self):
656656
return len([peer for peer in self.getpeerinfo() if peer['subver'] == P2P_SUBVERSION])
657657

658658
def disconnect_p2ps(self):
659-
"""Close all p2p connections to the node."""
659+
"""Close all p2p connections to the node.
660+
Use only after each p2p has sent a version message to ensure the wait works."""
660661
for p in self.p2ps:
661662
p.peer_disconnect()
662663
del self.p2ps[:]

0 commit comments

Comments
 (0)