Skip to content

Commit 38389dd

Browse files
author
MarcoFalke
committed
Merge #19252: test: wait for disconnect in disconnect_p2ps + bloomfilter test followups
9a40cfc [refactor] use waiting inside disconnect_p2ps (gzhao408) aeb9fb4 [test] wait for disconnect_p2ps to be reflected in getpeerinfo (gzhao408) e81942d [test] logging and style followups for bloomfilter tests (gzhao408) Pull request description: Followup to #19083 which adds bloomfilter-related tests. 1. Make test_node `disconnect_p2ps` wait until disconnection is complete to avoid race conditions (and not place the burden on tests) from MarcoFalke's [comment](bitcoin/bitcoin#19083 (comment)). And clean up any redundant `wait_until`s in the functional tests. 2. Clean up style + logging in p2p_filter.py and p2p_nobloomfilter_messages.py and jonatack's other [comments](bitcoin/bitcoin#19083 (review)) ACKs for top commit: jonatack: Code review ACK 9a40cfc from re-reviewing the diff and `git range-diff 5cafb46 8386ad5 9a40cfc` MarcoFalke: ACK 9a40cfc 🐂 Tree-SHA512: 2e14b1c12fc08a355bd5ccad7a2a734a4ccda4bc7dc7bac171cb57359819fc1599d764290729af74832fac3e2be258c5d406c701e78ab6d7262835859b9a7d87
2 parents 9a482d3 + 9a40cfc commit 38389dd

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

test/functional/p2p_filter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ def test_msg_mempool(self):
124124
self.log.info("Check that a node with bloom filters enabled services p2p mempool messages")
125125
filter_peer = P2PBloomFilter()
126126

127-
self.log.info("Create a tx relevant to the peer before connecting")
127+
self.log.debug("Create a tx relevant to the peer before connecting")
128128
filter_address = self.nodes[0].decodescript(filter_peer.watch_script_pubkey)['addresses'][0]
129129
txid = self.nodes[0].sendtoaddress(filter_address, 90)
130130

131-
self.log.info("Send a mempool msg after connecting and check that the tx is received")
131+
self.log.debug("Send a mempool msg after connecting and check that the tx is received")
132132
self.nodes[0].add_p2p_connection(filter_peer)
133133
filter_peer.send_and_ping(filter_peer.watch_filter_init)
134134
self.nodes[0].p2p.send_message(msg_mempool())
@@ -227,8 +227,8 @@ def run_test(self):
227227
self.test_frelay_false(filter_peer_without_nrelay)
228228
self.test_filter(filter_peer_without_nrelay)
229229

230-
self.log.info('Test msg_mempool')
231230
self.test_msg_mempool()
232231

232+
233233
if __name__ == '__main__':
234234
FilterTest().main()

test/functional/p2p_leak.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ def run_test(self):
132132

133133
self.nodes[0].disconnect_p2ps()
134134

135-
# Wait until all connections are closed
136-
wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 0)
137-
138135
# Make sure no unexpected messages came in
139136
assert no_version_bannode.unexpected_msg == False
140137
assert no_version_idlenode.unexpected_msg == False

test/functional/p2p_nobloomfilter_messages.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test invalid p2p messages for nodes with bloom filters disabled.
66
7-
Test that, when bloom filters are not enabled, nodes are disconnected if:
7+
Test that, when bloom filters are not enabled, peers are disconnected if:
88
1. They send a p2p mempool message
99
2. They send a p2p filterload message
1010
3. They send a p2p filteradd message
@@ -17,31 +17,32 @@
1717
from test_framework.util import assert_equal
1818

1919

20-
class P2PNobloomfilterMessages(BitcoinTestFramework):
20+
class P2PNoBloomFilterMessages(BitcoinTestFramework):
2121
def set_test_params(self):
2222
self.setup_clean_chain = True
2323
self.num_nodes = 1
2424
self.extra_args = [["-peerbloomfilters=0"]]
2525

2626
def test_message_causes_disconnect(self, message):
27-
# Add a p2p connection that sends a message and check that it disconnects
27+
"""Add a p2p connection that sends a message and check that it disconnects."""
2828
peer = self.nodes[0].add_p2p_connection(P2PInterface())
2929
peer.send_message(message)
3030
peer.wait_for_disconnect()
31-
assert_equal(len(self.nodes[0].getpeerinfo()), 0)
31+
assert_equal(self.nodes[0].getconnectioncount(), 0)
3232

3333
def run_test(self):
34-
self.log.info("Test that node is disconnected if it sends mempool message")
34+
self.log.info("Test that peer is disconnected if it sends mempool message")
3535
self.test_message_causes_disconnect(msg_mempool())
3636

37-
self.log.info("Test that node is disconnected if it sends filterload message")
37+
self.log.info("Test that peer is disconnected if it sends filterload message")
3838
self.test_message_causes_disconnect(msg_filterload())
3939

40-
self.log.info("Test that node is disconnected if it sends filteradd message")
40+
self.log.info("Test that peer is disconnected if it sends filteradd message")
4141
self.test_message_causes_disconnect(msg_filteradd(data=b'\xcc'))
4242

4343
self.log.info("Test that peer is disconnected if it sends a filterclear message")
4444
self.test_message_causes_disconnect(msg_filterclear())
4545

46+
4647
if __name__ == '__main__':
47-
P2PNobloomfilterMessages().main()
48+
P2PNoBloomFilterMessages().main()

test/functional/p2p_node_network_limited.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def run_test(self):
8383
assert_equal(node1.firstAddrnServices, expected_services)
8484

8585
self.nodes[0].disconnect_p2ps()
86-
node1.wait_for_disconnect()
8786

8887
# connect unsynced node 2 with pruned NODE_NETWORK_LIMITED peer
8988
# because node 2 is in IBD and node 0 is a NODE_NETWORK_LIMITED peer, sync must not be possible

test/functional/test_framework/test_node.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from .authproxy import JSONRPCException
2525
from .descriptors import descsum_create
26+
from .messages import MY_SUBVERSION
2627
from .util import (
2728
MAX_NODES,
2829
append_config,
@@ -549,11 +550,16 @@ def p2p(self):
549550
assert self.p2ps, self._node_msg("No p2p connection")
550551
return self.p2ps[0]
551552

553+
def num_connected_mininodes(self):
554+
"""Return number of test framework p2p connections to the node."""
555+
return len([peer for peer in self.getpeerinfo() if peer['subver'] == MY_SUBVERSION])
556+
552557
def disconnect_p2ps(self):
553558
"""Close all p2p connections to the node."""
554559
for p in self.p2ps:
555560
p.peer_disconnect()
556561
del self.p2ps[:]
562+
wait_until(lambda: self.num_connected_mininodes() == 0)
557563

558564

559565
class TestNodeCLIAttr:

0 commit comments

Comments
 (0)