Skip to content

Commit 1b04b55

Browse files
author
MarcoFalke
committed
Merge #13867: qa: Make extended tests pass on native Windows
fafe73a qa: Raise feature_help timeout to 5s (MarcoFalke) faabd7b qa: Use files for stdout/stderr to support Windows (MarcoFalke) facb56f qa: Run gen_rpcauth with sys.executable (MarcoFalke) fada896 qa: Close stdout and stderr file when node stops (MarcoFalke) Pull request description: ### qa: Close stdout and stderr file when node stops Since these files are potentially deleted by the test framework for cleanup, they should be closed first. Otherwise this will lead to errors on Windows when the tests finish successfully. Side note: After the patch, it is no longer possible to reopen the file on Windows (see https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile) ### qa: Run gen_rpcauth with sys.executable Similar to `test_runner.py`, the `sys.executable` needs to be passed down into subprocesses to pass on native Windows. (Should have no effect on Linux) ### qa: Use files for stdout/stderr to support Windows It seems that using PIPE is not supported on Windows. Also, it is easier to just use the files that capture the stdout and stderr within the test node class. Tree-SHA512: ec675012b10705978606b7fcbdb287c39a8e6e3732aae2fa4041d963a3c6993c6eac6a9a3cbd5479514e7d8017fe74c12235d1ed6fed2e8af8f3c71981e91864
2 parents a04888a + fafe73a commit 1b04b55

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

test/functional/feature_help.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Verify that starting bitcoin with -h works as expected."""
6-
import subprocess
76

87
from test_framework.test_framework import BitcoinTestFramework
98
from test_framework.util import assert_equal
@@ -17,41 +16,47 @@ def setup_network(self):
1716
self.add_nodes(self.num_nodes)
1817
# Don't start the node
1918

19+
def get_node_output(self, *, ret_code_expected):
20+
ret_code = self.nodes[0].process.wait(timeout=5)
21+
assert_equal(ret_code, ret_code_expected)
22+
self.nodes[0].stdout.seek(0)
23+
self.nodes[0].stderr.seek(0)
24+
out = self.nodes[0].stdout.read()
25+
err = self.nodes[0].stderr.read()
26+
self.nodes[0].stdout.close()
27+
self.nodes[0].stderr.close()
28+
29+
# Clean up TestNode state
30+
self.nodes[0].running = False
31+
self.nodes[0].process = None
32+
self.nodes[0].rpc_connected = False
33+
self.nodes[0].rpc = None
34+
35+
return out, err
36+
2037
def run_test(self):
2138
self.log.info("Start bitcoin with -h for help text")
22-
self.nodes[0].start(extra_args=['-h'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
39+
self.nodes[0].start(extra_args=['-h'])
2340
# Node should exit immediately and output help to stdout.
24-
ret_code = self.nodes[0].process.wait(timeout=1)
25-
assert_equal(ret_code, 0)
26-
output = self.nodes[0].process.stdout.read()
41+
output, _ = self.get_node_output(ret_code_expected=0)
2742
assert b'Options' in output
2843
self.log.info("Help text received: {} (...)".format(output[0:60]))
29-
self.nodes[0].running = False
3044

3145
self.log.info("Start bitcoin with -version for version information")
32-
self.nodes[0].start(extra_args=['-version'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
46+
self.nodes[0].start(extra_args=['-version'])
3347
# Node should exit immediately and output version to stdout.
34-
ret_code = self.nodes[0].process.wait(timeout=1)
35-
assert_equal(ret_code, 0)
36-
output = self.nodes[0].process.stdout.read()
48+
output, _ = self.get_node_output(ret_code_expected=0)
3749
assert b'version' in output
3850
self.log.info("Version text received: {} (...)".format(output[0:60]))
3951

4052
# Test that arguments not in the help results in an error
4153
self.log.info("Start bitcoind with -fakearg to make sure it does not start")
42-
self.nodes[0].start(extra_args=['-fakearg'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
54+
self.nodes[0].start(extra_args=['-fakearg'])
4355
# Node should exit immediately and output an error to stderr
44-
ret_code = self.nodes[0].process.wait(timeout=1)
45-
assert_equal(ret_code, 1)
46-
output = self.nodes[0].process.stderr.read()
56+
_, output = self.get_node_output(ret_code_expected=1)
4757
assert b'Error parsing command line arguments' in output
4858
self.log.info("Error message received: {} (...)".format(output[0:60]))
4959

50-
# Clean up TestNode state
51-
self.nodes[0].running = False
52-
self.nodes[0].process = None
53-
self.nodes[0].rpc_connected = False
54-
self.nodes[0].rpc = None
5560

5661
if __name__ == '__main__':
5762
HelpTest().main()

test/functional/rpc_users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from random import SystemRandom
1919
import string
2020
import configparser
21+
import sys
2122

2223

2324
class HTTPBasicsTest(BitcoinTestFramework):
@@ -36,7 +37,7 @@ def setup_chain(self):
3637
config = configparser.ConfigParser()
3738
config.read_file(open(self.options.configfile))
3839
gen_rpcauth = config['environment']['RPCAUTH']
39-
p = subprocess.Popen([gen_rpcauth, self.user], stdout=subprocess.PIPE, universal_newlines=True)
40+
p = subprocess.Popen([sys.executable, gen_rpcauth, self.user], stdout=subprocess.PIPE, universal_newlines=True)
4041
lines = p.stdout.read().splitlines()
4142
rpcauth3 = lines[1]
4243
self.password = lines[3]

test/functional/test_framework/test_node.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __getattr__(self, name):
122122
assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
123123
return getattr(self.rpc, name)
124124

125-
def start(self, extra_args=None, stdout=None, stderr=None, *args, **kwargs):
125+
def start(self, extra_args=None, *, stdout=None, stderr=None, **kwargs):
126126
"""Start the node."""
127127
if extra_args is None:
128128
extra_args = self.extra_args
@@ -143,7 +143,7 @@ def start(self, extra_args=None, stdout=None, stderr=None, *args, **kwargs):
143143
# add environment variable LIBC_FATAL_STDERR_=1 so that libc errors are written to stderr and not the terminal
144144
subp_env = dict(os.environ, LIBC_FATAL_STDERR_="1")
145145

146-
self.process = subprocess.Popen(self.args + extra_args, env=subp_env, stdout=stdout, stderr=stderr, *args, **kwargs)
146+
self.process = subprocess.Popen(self.args + extra_args, env=subp_env, stdout=stdout, stderr=stderr, **kwargs)
147147

148148
self.running = True
149149
self.log.debug("bitcoind started, waiting for RPC to come up")
@@ -200,6 +200,9 @@ def stop_node(self, expected_stderr=''):
200200
if stderr != expected_stderr:
201201
raise AssertionError("Unexpected stderr {} != {}".format(stderr, expected_stderr))
202202

203+
self.stdout.close()
204+
self.stderr.close()
205+
203206
del self.p2ps[:]
204207

205208
def is_node_stopped(self):

0 commit comments

Comments
 (0)