aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/test_framework
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2016-05-09 17:01:55 +0200
committerMarcoFalke <falke.marco@gmail.com>2016-05-09 17:06:44 +0200
commit4e14afe42fdd468d5de11df8cc13defdcb8e83f8 (patch)
tree4ebc19ab84c65fe2e161413ad8ae82dea6906986 /qa/rpc-tests/test_framework
parent3e90fe6534206412ea22beaa445cf20d28fbe718 (diff)
parentfad336648c848c7a4b3e32bae68ea9a22f97e668 (diff)
downloadbitcoin-4e14afe42fdd468d5de11df8cc13defdcb8e83f8.tar.xz
Merge #7971: [qa] Refactor test_framework and pull tester
fad3366 [qa] pull-tester: Adjust comment (MarcoFalke) fafb33c [qa] Stop other nodes, even when one fails to stop (MarcoFalke) 2222dae [qa] Update README.md (MarcoFalke) fabbf6b [qa] Refactor test_framework and pull tester (MarcoFalke)
Diffstat (limited to 'qa/rpc-tests/test_framework')
-rwxr-xr-xqa/rpc-tests/test_framework/test_framework.py4
-rw-r--r--qa/rpc-tests/test_framework/util.py28
2 files changed, 25 insertions, 7 deletions
diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py
index 0b6d1b6abc..4e72463096 100755
--- a/qa/rpc-tests/test_framework/test_framework.py
+++ b/qa/rpc-tests/test_framework/test_framework.py
@@ -115,7 +115,7 @@ class BitcoinTestFramework(object):
if self.options.trace_rpc:
import logging
- logging.basicConfig(level=logging.DEBUG)
+ logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
if self.options.coveragedir:
enable_coverage(self.options.coveragedir)
@@ -148,6 +148,8 @@ class BitcoinTestFramework(object):
except Exception as e:
print("Unexpected exception caught during testing: " + repr(e))
traceback.print_tb(sys.exc_info()[2])
+ except KeyboardInterrupt as e:
+ print("Exiting after " + repr(e))
if not self.options.noshutdown:
print("Stopping nodes")
diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py
index ea3931cef3..6dc685ea1b 100644
--- a/qa/rpc-tests/test_framework/util.py
+++ b/qa/rpc-tests/test_framework/util.py
@@ -16,6 +16,7 @@ from binascii import hexlify, unhexlify
from base64 import b64encode
from decimal import Decimal, ROUND_DOWN
import json
+import http.client
import random
import shutil
import subprocess
@@ -28,6 +29,13 @@ from .authproxy import AuthServiceProxy, JSONRPCException
COVERAGE_DIR = None
+# The maximum number of nodes a single test can spawn
+MAX_NODES = 8
+# Don't assign rpc or p2p ports lower than this
+PORT_MIN = 11000
+# The number of ports to "reserve" for p2p and rpc, each
+PORT_RANGE = 5000
+
#Set Mocktime default to OFF.
#MOCKTIME is only needed for scripts that use the
#cached version of the blockchain. If the cached
@@ -82,9 +90,11 @@ def get_rpc_proxy(url, node_number, timeout=None):
def p2p_port(n):
- return 11000 + n + os.getpid()%999
+ assert(n <= MAX_NODES)
+ return PORT_MIN + n + (MAX_NODES * os.getpid()) % (PORT_RANGE - 1 - MAX_NODES)
+
def rpc_port(n):
- return 12000 + n + os.getpid()%999
+ return PORT_MIN + PORT_RANGE + n + (MAX_NODES * os.getpid()) % (PORT_RANGE -1 - MAX_NODES)
def check_json_precision():
"""Make sure json library being used does not lose precision converting BTC values"""
@@ -292,8 +302,8 @@ def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None):
"""
Start multiple bitcoinds, return RPC connections to them
"""
- if extra_args is None: extra_args = [ None for i in range(num_nodes) ]
- if binary is None: binary = [ None for i in range(num_nodes) ]
+ if extra_args is None: extra_args = [ None for _ in range(num_nodes) ]
+ if binary is None: binary = [ None for _ in range(num_nodes) ]
rpcs = []
try:
for i in range(num_nodes):
@@ -307,13 +317,19 @@ def log_filename(dirname, n_node, logname):
return os.path.join(dirname, "node"+str(n_node), "regtest", logname)
def stop_node(node, i):
- node.stop()
+ try:
+ node.stop()
+ except http.client.CannotSendRequest as e:
+ print("WARN: Unable to stop node: " + repr(e))
bitcoind_processes[i].wait()
del bitcoind_processes[i]
def stop_nodes(nodes):
for node in nodes:
- node.stop()
+ try:
+ node.stop()
+ except http.client.CannotSendRequest as e:
+ print("WARN: Unable to stop node: " + repr(e))
del nodes[:] # Emptying array closes connections as a side effect
def set_node_times(nodes, t):