Skip to content

Commit f5a92bf

Browse files
committed
Print better errors, and add util stop_node() function.
1 parent e8097f7 commit f5a92bf

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

qa/rpc-tests/test_framework.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ def main(self):
6868

6969
success = True
7070

71+
except JSONRPCException as e:
72+
print("JSONRPC error: "+e.error['message'])
73+
traceback.print_tb(sys.exc_info()[2])
7174
except AssertionError as e:
7275
print("Assertion failed: "+e.message)
76+
traceback.print_tb(sys.exc_info()[2])
7377
except Exception as e:
7478
print("Unexpected exception caught during testing: "+str(e))
7579
traceback.print_tb(sys.exc_info()[2])

qa/rpc-tests/util.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def sync_mempools(rpc_connections):
5959
time.sleep(1)
6060

6161

62-
bitcoind_processes = []
62+
bitcoind_processes = {}
6363

6464
def initialize_datadir(dir, n):
6565
datadir = os.path.join(dir, "node"+str(n))
@@ -88,7 +88,7 @@ def initialize_chain(test_dir):
8888
args = [ "bitcoind", "-keypool=1", "-datadir="+datadir ]
8989
if i > 0:
9090
args.append("-connect=127.0.0.1:"+str(p2p_port(0)))
91-
bitcoind_processes.append(subprocess.Popen(args))
91+
bitcoind_processes[i] = subprocess.Popen(args)
9292
subprocess.check_call([ "bitcoin-cli", "-datadir="+datadir,
9393
"-rpcwait", "getblockcount"], stdout=devnull)
9494
devnull.close()
@@ -149,7 +149,7 @@ def start_node(i, dir, extra_args=None, rpchost=None):
149149
datadir = os.path.join(dir, "node"+str(i))
150150
args = [ "bitcoind", "-datadir="+datadir, "-keypool=1" ]
151151
if extra_args is not None: args.extend(extra_args)
152-
bitcoind_processes.append(subprocess.Popen(args))
152+
bitcoind_processes[i] = subprocess.Popen(args)
153153
devnull = open("/dev/null", "w+")
154154
subprocess.check_call([ "bitcoin-cli", "-datadir="+datadir] +
155155
_rpchost_to_args(rpchost) +
@@ -168,16 +168,21 @@ def start_nodes(num_nodes, dir, extra_args=None, rpchost=None):
168168
def debug_log(dir, n_node):
169169
return os.path.join(dir, "node"+str(n_node), "regtest", "debug.log")
170170

171+
def stop_node(node, i):
172+
node.stop()
173+
bitcoind_processes[i].wait()
174+
del bitcoind_processes[i]
175+
171176
def stop_nodes(nodes):
172177
for i in range(len(nodes)):
173178
nodes[i].stop()
174179
del nodes[:] # Emptying array closes connections as a side effect
175180

176181
def wait_bitcoinds():
177182
# Wait for all bitcoinds to cleanly exit
178-
for bitcoind in bitcoind_processes:
183+
for bitcoind in bitcoind_processes.values():
179184
bitcoind.wait()
180-
del bitcoind_processes[:]
185+
bitcoind_processes.clear()
181186

182187
def connect_nodes(from_connection, node_num):
183188
ip_port = "127.0.0.1:"+str(p2p_port(node_num))

0 commit comments

Comments
 (0)