From 0f6cd72237b5c819340e524681b5c95f6a81e0c2 Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Mon, 21 Nov 2022 18:10:20 -0500 Subject: [PATCH] test: Fix intermittent failure in rpc_net.py The wait in disconnect_p2ps checked for subver, which is unavailable for the peer that didn't send a version msg. --- test/functional/rpc_net.py | 5 +++-- test/functional/test_framework/test_node.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 65e3c82c87070..01334e2d57d58 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -112,7 +112,7 @@ def test_getpeerinfo(self): no_version_peer_conntime = int(time.time()) self.nodes[0].setmocktime(no_version_peer_conntime) with self.nodes[0].assert_debug_log([f"Added connection peer={no_version_peer_id}"]): - self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False) + no_version_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False) self.nodes[0].setmocktime(0) peer_info = self.nodes[0].getpeerinfo()[no_version_peer_id] peer_info.pop("addr") @@ -153,7 +153,8 @@ def test_getpeerinfo(self): "version": 0, }, ) - self.nodes[0].disconnect_p2ps() + no_version_peer.peer_disconnect() + self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 2) def test_getnettotals(self): self.log.info("Test getnettotals") diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 0075fa0996ef7..64edff15ae644 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -656,7 +656,8 @@ def num_test_p2p_connections(self): return len([peer for peer in self.getpeerinfo() if peer['subver'] == P2P_SUBVERSION]) def disconnect_p2ps(self): - """Close all p2p connections to the node.""" + """Close all p2p connections to the node. + Use only after each p2p has sent a version message to ensure the wait works.""" for p in self.p2ps: p.peer_disconnect() del self.p2ps[:]