aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'qa/rpc-tests/util.py')
-rw-r--r--qa/rpc-tests/util.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/qa/rpc-tests/util.py b/qa/rpc-tests/util.py
index 6184c1fbad..fa0700f1c8 100644
--- a/qa/rpc-tests/util.py
+++ b/qa/rpc-tests/util.py
@@ -55,6 +55,8 @@ def sync_mempools(rpc_connections):
time.sleep(1)
+bitcoind_processes = []
+
def initialize_chain(test_dir):
"""
Create (or copy from cache) a 200-block-long chain and
@@ -64,7 +66,6 @@ def initialize_chain(test_dir):
if not os.path.isdir(os.path.join("cache", "node0")):
# Create cache directories, run bitcoinds:
- bitcoinds = []
for i in range(4):
datadir = os.path.join("cache", "node"+str(i))
os.makedirs(datadir)
@@ -77,7 +78,7 @@ def initialize_chain(test_dir):
args = [ "bitcoind", "-keypool=1", "-datadir="+datadir ]
if i > 0:
args.append("-connect=127.0.0.1:"+str(START_P2P_PORT))
- bitcoinds.append(subprocess.Popen(args))
+ bitcoind_processes.append(subprocess.Popen(args))
subprocess.check_output([ "bitcoin-cli", "-datadir="+datadir,
"-rpcwait", "getblockcount"])
@@ -90,8 +91,6 @@ def initialize_chain(test_dir):
sys.stderr.write("Error connecting to "+url+"\n")
sys.exit(1)
- import pdb; pdb.set_trace()
-
# Create a 200-block-long chain; each of the 4 nodes
# gets 25 mature blocks and 25 immature.
for i in range(4):
@@ -100,17 +99,18 @@ def initialize_chain(test_dir):
for i in range(4):
rpcs[i].setgenerate(True, 25)
sync_blocks(rpcs)
- # Shut them down
+
+ # Shut them down, and remove debug.logs:
+ stop_nodes(rpcs)
+ wait_bitcoinds()
for i in range(4):
- rpcs[i].stop()
+ os.remove(debug_log("cache", i))
for i in range(4):
from_dir = os.path.join("cache", "node"+str(i))
to_dir = os.path.join(test_dir, "node"+str(i))
shutil.copytree(from_dir, to_dir)
-bitcoind_processes = []
-
def start_nodes(num_nodes, dir):
# Start bitcoinds, and wait for RPC interface to be up and running:
for i in range(num_nodes):
@@ -126,9 +126,19 @@ def start_nodes(num_nodes, dir):
rpc_connections.append(AuthServiceProxy(url))
return rpc_connections
-def stop_nodes():
- for process in bitcoind_processes:
- process.kill()
+def debug_log(dir, n_node):
+ return os.path.join(dir, "node"+str(n_node), "regtest", "debug.log")
+
+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:
+ bitcoind.wait()
+ del bitcoind_processes[:]
def connect_nodes(from_connection, node_num):
ip_port = "127.0.0.1:"+str(START_P2P_PORT+node_num)