Skip to content

Commit a433d8a

Browse files
committed
[tests] Update start/stop node functions to be private module functions
This commit marks the start/stop functions in util.py as private module functions. A future PR will remove these entirely and move the functionality directly into the BitcoinTestFramework class, but setting them as private in this PR will prevent anyone from accidentally calling them before that future PR is merged.
1 parent d8c218f commit a433d8a

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
p2p_port,
3232
rpc_url,
3333
set_node_times,
34-
start_node,
35-
start_nodes,
36-
stop_node,
37-
stop_nodes,
34+
_start_node,
35+
_start_nodes,
36+
_stop_node,
37+
_stop_nodes,
3838
sync_blocks,
3939
sync_mempools,
4040
wait_for_bitcoind_start,
@@ -91,7 +91,7 @@ def setup_nodes(self):
9191
extra_args = None
9292
if hasattr(self, "extra_args"):
9393
extra_args = self.extra_args
94-
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args)
94+
self.nodes = _start_nodes(self.num_nodes, self.options.tmpdir, extra_args)
9595

9696
def run_test(self):
9797
raise NotImplementedError
@@ -194,16 +194,16 @@ def main(self):
194194
# Public helper methods. These can be accessed by the subclass test scripts.
195195

196196
def start_node(self, i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, stderr=None):
197-
return start_node(i, dirname, extra_args, rpchost, timewait, binary, stderr)
197+
return _start_node(i, dirname, extra_args, rpchost, timewait, binary, stderr)
198198

199199
def start_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
200-
return start_nodes(num_nodes, dirname, extra_args, rpchost, timewait, binary)
200+
return _start_nodes(num_nodes, dirname, extra_args, rpchost, timewait, binary)
201201

202202
def stop_node(self, num_node):
203-
stop_node(self.nodes[num_node], num_node)
203+
_stop_node(self.nodes[num_node], num_node)
204204

205205
def stop_nodes(self):
206-
stop_nodes(self.nodes)
206+
_stop_nodes(self.nodes)
207207

208208
def split_network(self):
209209
"""

test/functional/test_framework/util.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ def wait_for_bitcoind_start(process, url, i):
227227
time.sleep(0.25)
228228

229229

230-
def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, stderr=None):
231-
"""
232-
Start a bitcoind and return RPC connection to it
233-
"""
230+
def _start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None, stderr=None):
231+
"""Start a bitcoind and return RPC connection to it
232+
233+
This function should only be called from within test_framework, not by individual test scripts."""
234+
234235
datadir = os.path.join(dirname, "node"+str(i))
235236
if binary is None:
236237
binary = os.getenv("BITCOIND", "bitcoind")
@@ -251,8 +252,8 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
251252
def assert_start_raises_init_error(i, dirname, extra_args=None, expected_msg=None):
252253
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
253254
try:
254-
node = start_node(i, dirname, extra_args, stderr=log_stderr)
255-
stop_node(node, i)
255+
node = _start_node(i, dirname, extra_args, stderr=log_stderr)
256+
_stop_node(node, i)
256257
except Exception as e:
257258
assert 'bitcoind exited' in str(e) #node must have shutdown
258259
if expected_msg is not None:
@@ -267,27 +268,32 @@ def assert_start_raises_init_error(i, dirname, extra_args=None, expected_msg=Non
267268
assert_msg = "bitcoind should have exited with expected error " + expected_msg
268269
raise AssertionError(assert_msg)
269270

270-
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
271-
"""
272-
Start multiple bitcoinds, return RPC connections to them
273-
"""
271+
def _start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
272+
"""Start multiple bitcoinds, return RPC connections to them
273+
274+
This function should only be called from within test_framework, not by individual test scripts."""
275+
274276
if extra_args is None: extra_args = [ None for _ in range(num_nodes) ]
275277
if binary is None: binary = [ None for _ in range(num_nodes) ]
276278
assert_equal(len(extra_args), num_nodes)
277279
assert_equal(len(binary), num_nodes)
278280
rpcs = []
279281
try:
280282
for i in range(num_nodes):
281-
rpcs.append(start_node(i, dirname, extra_args[i], rpchost, timewait=timewait, binary=binary[i]))
283+
rpcs.append(_start_node(i, dirname, extra_args[i], rpchost, timewait=timewait, binary=binary[i]))
282284
except: # If one node failed to start, stop the others
283-
stop_nodes(rpcs)
285+
_stop_nodes(rpcs)
284286
raise
285287
return rpcs
286288

287289
def log_filename(dirname, n_node, logname):
288290
return os.path.join(dirname, "node"+str(n_node), "regtest", logname)
289291

290-
def stop_node(node, i):
292+
def _stop_node(node, i):
293+
"""Stop a bitcoind test node
294+
295+
This function should only be called from within test_framework, not by individual test scripts."""
296+
291297
logger.debug("Stopping node %d" % i)
292298
try:
293299
node.stop()
@@ -297,9 +303,13 @@ def stop_node(node, i):
297303
assert_equal(return_code, 0)
298304
del bitcoind_processes[i]
299305

300-
def stop_nodes(nodes):
306+
def _stop_nodes(nodes):
307+
"""Stop multiple bitcoind test nodes
308+
309+
This function should only be called from within test_framework, not by individual test scripts."""
310+
301311
for i, node in enumerate(nodes):
302-
stop_node(node, i)
312+
_stop_node(node, i)
303313
assert not bitcoind_processes.values() # All connections must be gone now
304314

305315
def set_node_times(nodes, t):

0 commit comments

Comments
 (0)