Skip to content

Commit beee49b

Browse files
committed
[tests] Allow stderr to be tested against specified string
Allow bitcoind's stderr to be tested against a specified string on shutdown.
1 parent e503671 commit beee49b

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

test/functional/feature_includeconf.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
file.
1616
"""
1717
import os
18-
import tempfile
1918

20-
from test_framework.test_framework import BitcoinTestFramework, assert_equal
19+
from test_framework.test_framework import BitcoinTestFramework
2120

2221
class IncludeConfTest(BitcoinTestFramework):
2322
def set_test_params(self):
@@ -44,20 +43,18 @@ def run_test(self):
4443

4544
self.log.info("-includeconf cannot be used as command-line arg. subversion should still end with 'main; relative)/'")
4645
self.stop_node(0)
47-
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
48-
self.start_node(0, extra_args=["-includeconf=relative2.conf"], stderr=log_stderr)
4946

50-
subversion = self.nodes[0].getnetworkinfo()["subversion"]
51-
assert subversion.endswith("main; relative)/")
52-
log_stderr.seek(0)
53-
stderr = log_stderr.read().decode('utf-8').strip()
54-
assert_equal(stderr, 'warning: -includeconf cannot be used from commandline; ignoring -includeconf=relative2.conf')
47+
self.start_node(0, extra_args=["-includeconf=relative2.conf"])
48+
49+
subversion = self.nodes[0].getnetworkinfo()["subversion"]
50+
assert subversion.endswith("main; relative)/")
51+
self.stop_node(0, expected_stderr="warning: -includeconf cannot be used from commandline; ignoring -includeconf=relative2.conf")
5552

5653
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
5754
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
5855
f.write("includeconf=relative2.conf\n")
5956

60-
self.restart_node(0)
57+
self.start_node(0)
6158

6259
subversion = self.nodes[0].getnetworkinfo()["subversion"]
6360
assert subversion.endswith("main; relative)/")

test/functional/test_framework/test_framework.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ def start_nodes(self, extra_args=None, *args, **kwargs):
289289
for node in self.nodes:
290290
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
291291

292-
def stop_node(self, i):
292+
def stop_node(self, i, expected_stderr=''):
293293
"""Stop a bitcoind test node"""
294-
self.nodes[i].stop_node()
294+
self.nodes[i].stop_node(expected_stderr)
295295
self.nodes[i].wait_until_stopped()
296296

297297
def stop_nodes(self):

test/functional/test_framework/test_node.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def get_wallet_rpc(self, wallet_name):
188188
wallet_path = "wallet/%s" % wallet_name
189189
return self.rpc / wallet_path
190190

191-
def stop_node(self):
191+
def stop_node(self, expected_stderr=''):
192192
"""Stop the node."""
193193
if not self.running:
194194
return
@@ -197,6 +197,13 @@ def stop_node(self):
197197
self.stop()
198198
except http.client.CannotSendRequest:
199199
self.log.exception("Unable to stop node.")
200+
201+
# Check that stderr is as expected
202+
self.stderr.seek(0)
203+
stderr = self.stderr.read().decode('utf-8').strip()
204+
if stderr != expected_stderr:
205+
raise AssertionError("Unexpected stderr {} != {}".format(stderr, expected_stderr))
206+
200207
del self.p2ps[:]
201208

202209
def is_node_stopped(self):

0 commit comments

Comments
 (0)