Skip to content

Commit ccccc59

Browse files
author
MarcoFalke
committed
[qa] Add option --portseed to test_framework
1 parent fa494de commit ccccc59

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,10 @@ def get_next(self):
242242
# Add tests
243243
self.num_running += 1
244244
t = self.test_list.pop(0)
245+
port_seed = ["--portseed=%s" % len(self.test_list)]
245246
self.jobs.append((t,
246247
time.time(),
247-
subprocess.Popen((RPC_TESTS_DIR + t).split() + self.flags,
248+
subprocess.Popen((RPC_TESTS_DIR + t).split() + self.flags + port_seed,
248249
universal_newlines=True,
249250
stdout=subprocess.PIPE,
250251
stderr=subprocess.PIPE)))

qa/rpc-tests/test_framework/test_framework.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
# Base class for RPC testing
77

8-
# Add python-bitcoinrpc to module search path:
8+
import logging
9+
import optparse
910
import os
1011
import sys
11-
1212
import shutil
1313
import tempfile
1414
import traceback
@@ -25,8 +25,9 @@
2525
enable_coverage,
2626
check_json_precision,
2727
initialize_chain_clean,
28+
PortSeed,
2829
)
29-
from .authproxy import AuthServiceProxy, JSONRPCException
30+
from .authproxy import JSONRPCException
3031

3132

3233
class BitcoinTestFramework(object):
@@ -95,7 +96,6 @@ def join_network(self):
9596
self.setup_network(False)
9697

9798
def main(self):
98-
import optparse
9999

100100
parser = optparse.OptionParser(usage="%prog [options]")
101101
parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
@@ -108,18 +108,21 @@ def main(self):
108108
help="Root directory for datadirs")
109109
parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true",
110110
help="Print out all RPC calls as they are made")
111+
parser.add_option("--portseed", dest="port_seed", default=os.getpid(), type='int',
112+
help="The seed to use for assigning port numbers (default: current process id)")
111113
parser.add_option("--coveragedir", dest="coveragedir",
112114
help="Write tested RPC commands into this directory")
113115
self.add_options(parser)
114116
(self.options, self.args) = parser.parse_args()
115117

116118
if self.options.trace_rpc:
117-
import logging
118119
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
119120

120121
if self.options.coveragedir:
121122
enable_coverage(self.options.coveragedir)
122123

124+
PortSeed.n = self.options.port_seed
125+
123126
os.environ['PATH'] = self.options.srcdir+":"+self.options.srcdir+"/qt:"+os.environ['PATH']
124127

125128
check_json_precision()

qa/rpc-tests/test_framework/util.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# Helpful routines for regression testing
99
#
1010

11-
# Add python-bitcoinrpc to module search path:
1211
import os
1312
import sys
1413

@@ -36,6 +35,11 @@
3635
# The number of ports to "reserve" for p2p and rpc, each
3736
PORT_RANGE = 5000
3837

38+
39+
class PortSeed:
40+
# Must be initialized with a unique integer for each process
41+
n = None
42+
3943
#Set Mocktime default to OFF.
4044
#MOCKTIME is only needed for scripts that use the
4145
#cached version of the blockchain. If the cached
@@ -91,10 +95,10 @@ def get_rpc_proxy(url, node_number, timeout=None):
9195

9296
def p2p_port(n):
9397
assert(n <= MAX_NODES)
94-
return PORT_MIN + n + (MAX_NODES * os.getpid()) % (PORT_RANGE - 1 - MAX_NODES)
98+
return PORT_MIN + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)
9599

96100
def rpc_port(n):
97-
return PORT_MIN + PORT_RANGE + n + (MAX_NODES * os.getpid()) % (PORT_RANGE -1 - MAX_NODES)
101+
return PORT_MIN + PORT_RANGE + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)
98102

99103
def check_json_precision():
100104
"""Make sure json library being used does not lose precision converting BTC values"""

0 commit comments

Comments
 (0)