[qa] Add option --portseed to test_framework

This commit is contained in:
MarcoFalke 2016-05-09 19:55:49 +02:00
parent fa494dec79
commit ccccc591a4
3 changed files with 17 additions and 9 deletions

View file

@ -242,9 +242,10 @@ class RPCTestHandler:
# Add tests # Add tests
self.num_running += 1 self.num_running += 1
t = self.test_list.pop(0) t = self.test_list.pop(0)
port_seed = ["--portseed=%s" % len(self.test_list)]
self.jobs.append((t, self.jobs.append((t,
time.time(), time.time(),
subprocess.Popen((RPC_TESTS_DIR + t).split() + self.flags, subprocess.Popen((RPC_TESTS_DIR + t).split() + self.flags + port_seed,
universal_newlines=True, universal_newlines=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE))) stderr=subprocess.PIPE)))

View file

@ -5,10 +5,10 @@
# Base class for RPC testing # Base class for RPC testing
# Add python-bitcoinrpc to module search path: import logging
import optparse
import os import os
import sys import sys
import shutil import shutil
import tempfile import tempfile
import traceback import traceback
@ -25,8 +25,9 @@ from .util import (
enable_coverage, enable_coverage,
check_json_precision, check_json_precision,
initialize_chain_clean, initialize_chain_clean,
PortSeed,
) )
from .authproxy import AuthServiceProxy, JSONRPCException from .authproxy import JSONRPCException
class BitcoinTestFramework(object): class BitcoinTestFramework(object):
@ -95,7 +96,6 @@ class BitcoinTestFramework(object):
self.setup_network(False) self.setup_network(False)
def main(self): def main(self):
import optparse
parser = optparse.OptionParser(usage="%prog [options]") parser = optparse.OptionParser(usage="%prog [options]")
parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true", parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
@ -108,18 +108,21 @@ class BitcoinTestFramework(object):
help="Root directory for datadirs") help="Root directory for datadirs")
parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true", parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true",
help="Print out all RPC calls as they are made") help="Print out all RPC calls as they are made")
parser.add_option("--portseed", dest="port_seed", default=os.getpid(), type='int',
help="The seed to use for assigning port numbers (default: current process id)")
parser.add_option("--coveragedir", dest="coveragedir", parser.add_option("--coveragedir", dest="coveragedir",
help="Write tested RPC commands into this directory") help="Write tested RPC commands into this directory")
self.add_options(parser) self.add_options(parser)
(self.options, self.args) = parser.parse_args() (self.options, self.args) = parser.parse_args()
if self.options.trace_rpc: if self.options.trace_rpc:
import logging
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
if self.options.coveragedir: if self.options.coveragedir:
enable_coverage(self.options.coveragedir) enable_coverage(self.options.coveragedir)
PortSeed.n = self.options.port_seed
os.environ['PATH'] = self.options.srcdir+":"+self.options.srcdir+"/qt:"+os.environ['PATH'] os.environ['PATH'] = self.options.srcdir+":"+self.options.srcdir+"/qt:"+os.environ['PATH']
check_json_precision() check_json_precision()

View file

@ -8,7 +8,6 @@
# Helpful routines for regression testing # Helpful routines for regression testing
# #
# Add python-bitcoinrpc to module search path:
import os import os
import sys import sys
@ -36,6 +35,11 @@ PORT_MIN = 11000
# The number of ports to "reserve" for p2p and rpc, each # The number of ports to "reserve" for p2p and rpc, each
PORT_RANGE = 5000 PORT_RANGE = 5000
class PortSeed:
# Must be initialized with a unique integer for each process
n = None
#Set Mocktime default to OFF. #Set Mocktime default to OFF.
#MOCKTIME is only needed for scripts that use the #MOCKTIME is only needed for scripts that use the
#cached version of the blockchain. If the cached #cached version of the blockchain. If the cached
@ -91,10 +95,10 @@ def get_rpc_proxy(url, node_number, timeout=None):
def p2p_port(n): def p2p_port(n):
assert(n <= MAX_NODES) assert(n <= MAX_NODES)
return PORT_MIN + n + (MAX_NODES * os.getpid()) % (PORT_RANGE - 1 - MAX_NODES) return PORT_MIN + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)
def rpc_port(n): def rpc_port(n):
return PORT_MIN + PORT_RANGE + n + (MAX_NODES * os.getpid()) % (PORT_RANGE -1 - MAX_NODES) return PORT_MIN + PORT_RANGE + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)
def check_json_precision(): def check_json_precision():
"""Make sure json library being used does not lose precision converting BTC values""" """Make sure json library being used does not lose precision converting BTC values"""