Skip to content

Commit

Permalink
Merge bitcoin#15415: [test] functional: allow custom cwd, use tmpdir …
Browse files Browse the repository at this point in the history
…as default

e3e1a56 [test] functional: set cwd of nodes to tmpdir (Sjors Provoost)

Pull request description:

  Any process launched by bitcoind will have `self.datadir` as its `cwd`.

Tree-SHA512: 0b311643bb96c7dc2f693774620173243b3add40bf373284695af2f0071823b23485289fd2ffe152b7f63e0bfe989b16720077cfc2ce33905f9b8e7f2630f3c0
  • Loading branch information
MarcoFalke authored and Munkybooty committed Sep 7, 2021
1 parent dc8cd68 commit aee2b0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion test/functional/test_framework/test_framework.py
Expand Up @@ -332,7 +332,7 @@ def add_nodes(self, num_nodes, extra_args=None, *, rpchost=None, binary=None):
assert_equal(len(binary), num_nodes)
for i in range(num_nodes):
numnode = len(self.nodes)
self.nodes.append(TestNode(numnode, get_datadir_path(self.options.tmpdir, numnode), self.extra_args_from_options, chain=self.chain, rpchost=rpchost, timewait=self.rpc_timeout, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli, start_perf=self.options.perf))
self.nodes.append(TestNode(numnode, get_datadir_path(self.options.tmpdir, numnode), self.extra_args_from_options, chain=self.chain, rpchost=rpchost, timewait=self.rpc_timeout, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, mocktime=self.mocktime, coverage_dir=self.options.coveragedir,cwd=self.options.tmpdir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli, start_perf=self.options.perf))

def start_node(self, i, *args, **kwargs):
"""Start a dashd"""
Expand Down Expand Up @@ -509,6 +509,7 @@ def _initialize_chain(self, extra_args=None):
bitcoin_cli=self.options.bitcoincli,
mocktime=self.mocktime,
coverage_dir=None,
cwd=self.options.tmpdir,
))
self.nodes[i].args = args
self.start_node(i)
Expand Down
12 changes: 8 additions & 4 deletions test/functional/test_framework/test_node.py
Expand Up @@ -62,7 +62,7 @@ class TestNode():
To make things easier for the test writer, any unrecognised messages will
be dispatched to the RPC connection."""

def __init__(self, i, datadir, extra_args_from_options, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False, start_perf=False):
def __init__(self, i, datadir, extra_args_from_options, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, mocktime, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False):
"""
Kwargs:
start_perf (bool): If True, begin profiling the node with `perf` as soon as
Expand All @@ -81,7 +81,8 @@ def __init__(self, i, datadir, extra_args_from_options, *, chain, rpchost, timew
self.binary = bitcoind
self.coverage_dir = coverage_dir
self.mocktime = mocktime
if extra_conf != None:
self.cwd = cwd
if extra_conf is not None:
append_config(datadir, extra_conf)
# Most callers will just need to add extra args to the standard list below.
# For those callers that need more flexibity, they can just set the args property directly.
Expand Down Expand Up @@ -182,7 +183,7 @@ def __getattr__(self, name):
assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
return getattr(self.rpc, name)

def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs):
def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, **kwargs):
"""Start the node."""
if extra_args is None:
extra_args = self.extra_args
Expand All @@ -199,6 +200,9 @@ def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs):
if self.mocktime != 0:
all_args = all_args + ["-mocktime=%d" % self.mocktime]

if cwd is None:
cwd = self.cwd

# Delete any existing cookie file -- if such a file exists (eg due to
# unclean shutdown), it will get overwritten anyway by dashd, and
# potentially interfere with our attempt to authenticate
Expand All @@ -207,7 +211,7 @@ def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs):
# add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal
subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1")

self.process = subprocess.Popen(all_args, env=subp_env, stdout=stdout, stderr=stderr, **kwargs)
self.process = subprocess.Popen(all_args, env=subp_env, stdout=stdout, stderr=stderr, cwd=cwd, **kwargs)

self.running = True
self.log.debug("dashd started, waiting for RPC to come up")
Expand Down

0 comments on commit aee2b0d

Please sign in to comment.