Skip to content

Commit faaa7db

Browse files
author
MarcoFalke
committed
qa: Only allow disconnecting all NodeConns
1 parent f7388e9 commit faaa7db

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

test/functional/maxuploadtarget.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_test(self):
5454
# p2p_conns[2] will test resetting the counters
5555
p2p_conns = []
5656

57-
for i in range(3):
57+
for _ in range(3):
5858
p2p_conns.append(self.nodes[0].add_p2p_connection(TestNode()))
5959

6060
NetworkThread().start() # Start up network handling in another thread
@@ -139,8 +139,7 @@ def run_test(self):
139139

140140
self.log.info("Peer 2 able to download old block")
141141

142-
for i in range(3):
143-
self.nodes[0].disconnect_p2p()
142+
self.nodes[0].disconnect_p2ps()
144143

145144
#stop and start node 0 with 1MB maxuploadtarget, whitelist 127.0.0.1
146145
self.log.info("Restarting nodes with -whitelist=127.0.0.1")

test/functional/p2p-acceptblock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def run_test(self):
206206
# The node should have requested the blocks at some point, so
207207
# disconnect/reconnect first
208208

209-
self.nodes[0].disconnect_p2p()
209+
self.nodes[0].disconnect_p2ps()
210210
test_node = self.nodes[0].add_p2p_connection(NodeConnCB())
211211

212212
test_node.wait_for_verack()
@@ -291,7 +291,7 @@ def run_test(self):
291291
except AssertionError:
292292
test_node.wait_for_disconnect()
293293

294-
self.nodes[0].disconnect_p2p()
294+
self.nodes[0].disconnect_p2ps()
295295
test_node = self.nodes[0].add_p2p_connection(NodeConnCB())
296296

297297
NetworkThread().start() # Start up network handling in another thread

test/functional/p2p-leaktests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ def run_test(self):
126126
assert not unsupported_service_bit5_node.connected
127127
assert not unsupported_service_bit7_node.connected
128128

129-
for _ in range(5):
130-
self.nodes[0].disconnect_p2p()
129+
self.nodes[0].disconnect_p2ps()
131130

132131
# Wait until all connections are closed
133132
wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 0)

test/functional/test_framework/test_node.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ def p2p(self):
182182
assert self.p2ps, "No p2p connection"
183183
return self.p2ps[0]
184184

185-
def disconnect_p2p(self, index=0):
186-
"""Close the p2p connection to the node."""
187-
# Connection could have already been closed by other end. Calling disconnect_p2p()
188-
# on an already disconnected p2p connection is not an error.
189-
if self.p2ps[index].connection is not None:
190-
self.p2ps[index].connection.disconnect_node()
191-
del self.p2ps[index]
185+
def disconnect_p2ps(self):
186+
"""Close all p2p connections to the node."""
187+
for p in self.p2ps:
188+
# Connection could have already been closed by other end.
189+
if p.connection is not None:
190+
p.connection.disconnect_node()
191+
self.p2ps = []
192+
192193

193194
class TestNodeCLI():
194195
"""Interface to bitcoin-cli for an individual node"""

0 commit comments

Comments
 (0)