Skip to content

Commit fa4cd2e

Browse files
author
MarcoFalke
committed
qa: Check return code when stopping nodes
This includes work by jnewbery
1 parent 8ad31f9 commit fa4cd2e

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

qa/rpc-tests/fundrawtransaction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ def run_test(self):
469469
# locked wallet test
470470
self.nodes[1].encryptwallet("test")
471471
self.nodes.pop(1)
472-
stop_nodes(self.nodes)
472+
stop_node(self.nodes[0], 0)
473+
stop_node(self.nodes[1], 2)
474+
stop_node(self.nodes[2], 3)
473475

474476
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
475477
# This test is not meant to test fee estimation and we'd like

qa/rpc-tests/rpcbind_test.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ def run_bind_test(self, allow_ips, connect_to, addresses, expected):
3535
base_args += ['-rpcallowip=' + x for x in allow_ips]
3636
binds = ['-rpcbind='+addr for addr in addresses]
3737
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [base_args + binds], connect_to)
38-
try:
39-
pid = bitcoind_processes[0].pid
40-
assert_equal(set(get_bind_addrs(pid)), set(expected))
41-
finally:
42-
stop_nodes(self.nodes)
38+
pid = bitcoind_processes[0].pid
39+
assert_equal(set(get_bind_addrs(pid)), set(expected))
40+
stop_nodes(self.nodes)
4341

4442
def run_allowip_test(self, allow_ips, rpchost, rpcport):
4543
'''
@@ -48,13 +46,10 @@ def run_allowip_test(self, allow_ips, rpchost, rpcport):
4846
'''
4947
base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips]
5048
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [base_args])
51-
try:
52-
# connect to node through non-loopback interface
53-
node = get_rpc_proxy(rpc_url(0, "%s:%d" % (rpchost, rpcport)), 0)
54-
node.getnetworkinfo()
55-
finally:
56-
node = None # make sure connection will be garbage collected and closed
57-
stop_nodes(self.nodes)
49+
# connect to node through non-loopback interface
50+
node = get_rpc_proxy(rpc_url(0, "%s:%d" % (rpchost, rpcport)), 0)
51+
node.getnetworkinfo()
52+
stop_nodes(self.nodes)
5853

5954
def run_test(self):
6055
# due to OS-specific network stats queries, this test works only on Linux

qa/rpc-tests/test_framework/util.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,28 +375,19 @@ def stop_node(node, i):
375375
node.stop()
376376
except http.client.CannotSendRequest as e:
377377
print("WARN: Unable to stop node: " + repr(e))
378-
bitcoind_processes[i].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
378+
return_code = bitcoind_processes[i].wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
379+
assert_equal(return_code, 0)
379380
del bitcoind_processes[i]
380381

381382
def stop_nodes(nodes):
382-
for node in nodes:
383-
try:
384-
node.stop()
385-
except http.client.CannotSendRequest as e:
386-
print("WARN: Unable to stop node: " + repr(e))
387-
del nodes[:] # Emptying array closes connections as a side effect
388-
wait_bitcoinds()
383+
for i, node in enumerate(nodes):
384+
stop_node(node, i)
385+
assert not bitcoind_processes.values() # All connections must be gone now
389386

390387
def set_node_times(nodes, t):
391388
for node in nodes:
392389
node.setmocktime(t)
393390

394-
def wait_bitcoinds():
395-
# Wait for all bitcoinds to cleanly exit
396-
for bitcoind in bitcoind_processes.values():
397-
bitcoind.wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
398-
bitcoind_processes.clear()
399-
400391
def connect_nodes(from_connection, node_num):
401392
ip_port = "127.0.0.1:"+str(p2p_port(node_num))
402393
from_connection.addnode(ip_port, "onetry")

0 commit comments

Comments
 (0)