Skip to content

Commit cc87ee4

Browse files
committed
test: fix intermittent failure in rpc_setban.py --v2transport
When initiating a v2 connection and being immediately disconnected, a node cannot know if the disconnect happens because the peer only supports v1, or because it has banned you, so it schedules to reconnect with v1. If the test doesn't wait for that, the reconnect can happen at a bad time, resulting in failure in a later connect_nodes call. Also add the test with --v2transport to the test runner.
1 parent 5b8c597 commit cc87ee4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

test/functional/rpc_setban.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the setban rpc call."""
66

7+
from contextlib import ExitStack
78
from test_framework.test_framework import BitcoinTestFramework
89
from test_framework.util import (
910
p2p_port,
@@ -29,7 +30,13 @@ def run_test(self):
2930
self.nodes[1].setban("127.0.0.1", "add")
3031

3132
# Node 0 should not be able to reconnect
32-
with self.nodes[1].assert_debug_log(expected_msgs=['dropped (banned)\n'], timeout=50):
33+
context = ExitStack()
34+
context.enter_context(self.nodes[1].assert_debug_log(expected_msgs=['dropped (banned)\n'], timeout=50))
35+
# When disconnected right after connecting, a v2 node will attempt to reconnect with v1.
36+
# Wait for that to happen so that it cannot mess with later tests.
37+
if self.options.v2transport:
38+
context.enter_context(self.nodes[0].assert_debug_log(expected_msgs=['trying v1 connection'], timeout=50))
39+
with context:
3340
self.restart_node(1, [])
3441
self.nodes[0].addnode("127.0.0.1:" + str(p2p_port(1)), "onetry")
3542

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
'p2p_nobloomfilter_messages.py',
255255
'p2p_filter.py',
256256
'rpc_setban.py',
257+
'rpc_setban.py --v2transport',
257258
'p2p_blocksonly.py',
258259
'mining_prioritisetransaction.py',
259260
'p2p_invalid_locator.py',

0 commit comments

Comments
 (0)