Skip to content

Commit

Permalink
Print better errors, and add util stop_node() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinandresen committed Jul 9, 2014
1 parent e8097f7 commit f5a92bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions qa/rpc-tests/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ def main(self):

success = True

except JSONRPCException as e:
print("JSONRPC error: "+e.error['message'])
traceback.print_tb(sys.exc_info()[2])
except AssertionError as e:
print("Assertion failed: "+e.message)
traceback.print_tb(sys.exc_info()[2])
except Exception as e:
print("Unexpected exception caught during testing: "+str(e))
traceback.print_tb(sys.exc_info()[2])
Expand Down
15 changes: 10 additions & 5 deletions qa/rpc-tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def sync_mempools(rpc_connections):
time.sleep(1)


bitcoind_processes = []
bitcoind_processes = {}

def initialize_datadir(dir, n):
datadir = os.path.join(dir, "node"+str(n))
Expand Down Expand Up @@ -88,7 +88,7 @@ def initialize_chain(test_dir):
args = [ "bitcoind", "-keypool=1", "-datadir="+datadir ]
if i > 0:
args.append("-connect=127.0.0.1:"+str(p2p_port(0)))
bitcoind_processes.append(subprocess.Popen(args))
bitcoind_processes[i] = subprocess.Popen(args)
subprocess.check_call([ "bitcoin-cli", "-datadir="+datadir,
"-rpcwait", "getblockcount"], stdout=devnull)
devnull.close()
Expand Down Expand Up @@ -149,7 +149,7 @@ def start_node(i, dir, extra_args=None, rpchost=None):
datadir = os.path.join(dir, "node"+str(i))
args = [ "bitcoind", "-datadir="+datadir, "-keypool=1" ]
if extra_args is not None: args.extend(extra_args)
bitcoind_processes.append(subprocess.Popen(args))
bitcoind_processes[i] = subprocess.Popen(args)
devnull = open("/dev/null", "w+")
subprocess.check_call([ "bitcoin-cli", "-datadir="+datadir] +
_rpchost_to_args(rpchost) +
Expand All @@ -168,16 +168,21 @@ def start_nodes(num_nodes, dir, extra_args=None, rpchost=None):
def debug_log(dir, n_node):
return os.path.join(dir, "node"+str(n_node), "regtest", "debug.log")

def stop_node(node, i):
node.stop()
bitcoind_processes[i].wait()
del bitcoind_processes[i]

def stop_nodes(nodes):
for i in range(len(nodes)):
nodes[i].stop()
del nodes[:] # Emptying array closes connections as a side effect

def wait_bitcoinds():
# Wait for all bitcoinds to cleanly exit
for bitcoind in bitcoind_processes:
for bitcoind in bitcoind_processes.values():
bitcoind.wait()
del bitcoind_processes[:]
bitcoind_processes.clear()

def connect_nodes(from_connection, node_num):
ip_port = "127.0.0.1:"+str(p2p_port(node_num))
Expand Down

0 comments on commit f5a92bf

Please sign in to comment.