[tests] Allow stderr to be tested against specified string
Allow bitcoind's stderr to be tested against a specified string on shutdown.
This commit is contained in:
parent
e5036715c8
commit
beee49ba1f
|
@ -15,9 +15,8 @@ Verify that:
|
||||||
file.
|
file.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from test_framework.test_framework import BitcoinTestFramework, assert_equal
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
|
||||||
class IncludeConfTest(BitcoinTestFramework):
|
class IncludeConfTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
|
@ -44,20 +43,18 @@ class IncludeConfTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.log.info("-includeconf cannot be used as command-line arg. subversion should still end with 'main; relative)/'")
|
self.log.info("-includeconf cannot be used as command-line arg. subversion should still end with 'main; relative)/'")
|
||||||
self.stop_node(0)
|
self.stop_node(0)
|
||||||
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
|
|
||||||
self.start_node(0, extra_args=["-includeconf=relative2.conf"], stderr=log_stderr)
|
|
||||||
|
|
||||||
subversion = self.nodes[0].getnetworkinfo()["subversion"]
|
self.start_node(0, extra_args=["-includeconf=relative2.conf"])
|
||||||
assert subversion.endswith("main; relative)/")
|
|
||||||
log_stderr.seek(0)
|
subversion = self.nodes[0].getnetworkinfo()["subversion"]
|
||||||
stderr = log_stderr.read().decode('utf-8').strip()
|
assert subversion.endswith("main; relative)/")
|
||||||
assert_equal(stderr, 'warning: -includeconf cannot be used from commandline; ignoring -includeconf=relative2.conf')
|
self.stop_node(0, expected_stderr="warning: -includeconf cannot be used from commandline; ignoring -includeconf=relative2.conf")
|
||||||
|
|
||||||
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
|
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
|
||||||
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
|
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
|
||||||
f.write("includeconf=relative2.conf\n")
|
f.write("includeconf=relative2.conf\n")
|
||||||
|
|
||||||
self.restart_node(0)
|
self.start_node(0)
|
||||||
|
|
||||||
subversion = self.nodes[0].getnetworkinfo()["subversion"]
|
subversion = self.nodes[0].getnetworkinfo()["subversion"]
|
||||||
assert subversion.endswith("main; relative)/")
|
assert subversion.endswith("main; relative)/")
|
||||||
|
|
|
@ -289,9 +289,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||||
for node in self.nodes:
|
for node in self.nodes:
|
||||||
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
|
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
|
||||||
|
|
||||||
def stop_node(self, i):
|
def stop_node(self, i, expected_stderr=''):
|
||||||
"""Stop a bitcoind test node"""
|
"""Stop a bitcoind test node"""
|
||||||
self.nodes[i].stop_node()
|
self.nodes[i].stop_node(expected_stderr)
|
||||||
self.nodes[i].wait_until_stopped()
|
self.nodes[i].wait_until_stopped()
|
||||||
|
|
||||||
def stop_nodes(self):
|
def stop_nodes(self):
|
||||||
|
|
|
@ -188,7 +188,7 @@ class TestNode():
|
||||||
wallet_path = "wallet/%s" % wallet_name
|
wallet_path = "wallet/%s" % wallet_name
|
||||||
return self.rpc / wallet_path
|
return self.rpc / wallet_path
|
||||||
|
|
||||||
def stop_node(self):
|
def stop_node(self, expected_stderr=''):
|
||||||
"""Stop the node."""
|
"""Stop the node."""
|
||||||
if not self.running:
|
if not self.running:
|
||||||
return
|
return
|
||||||
|
@ -197,6 +197,13 @@ class TestNode():
|
||||||
self.stop()
|
self.stop()
|
||||||
except http.client.CannotSendRequest:
|
except http.client.CannotSendRequest:
|
||||||
self.log.exception("Unable to stop node.")
|
self.log.exception("Unable to stop node.")
|
||||||
|
|
||||||
|
# Check that stderr is as expected
|
||||||
|
self.stderr.seek(0)
|
||||||
|
stderr = self.stderr.read().decode('utf-8').strip()
|
||||||
|
if stderr != expected_stderr:
|
||||||
|
raise AssertionError("Unexpected stderr {} != {}".format(stderr, expected_stderr))
|
||||||
|
|
||||||
del self.p2ps[:]
|
del self.p2ps[:]
|
||||||
|
|
||||||
def is_node_stopped(self):
|
def is_node_stopped(self):
|
||||||
|
|
Loading…
Reference in New Issue