Skip to content

Commit 15c3bb4

Browse files
committed
Merge #12904: [qa] Ensure bitcoind processes are cleaned up when tests end
e36a0c0 [qa] Ensure bitcoind processes are cleaned up when tests end (Suhas Daftuar) Pull request description: When tests fail (such as due to a bug in the test, race condition, etc), it's possible that we could follow code paths that bypass our normal node shutdown that occurs in `TestNode.stop_node`. Add a destructor to `TestNode` that cleans this up. Tree-SHA512: 72e04bc21462ebd0cb346fd1fe0540da454acfbad41923a0b06ea2317e9045b68e58f9adb02d8200891aca89a9d03a022eb72282aeb31a3b3afe7c6843a4b450
2 parents 25c56cd + e36a0c0 commit 15c3bb4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

test/functional/feature_help.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ def run_test(self):
3636
output = self.nodes[0].process.stdout.read()
3737
assert b'version' in output
3838
self.log.info("Version text received: {} (...)".format(output[0:60]))
39+
# Clean up TestNode state
3940
self.nodes[0].running = False
41+
self.nodes[0].process = None
42+
self.nodes[0].rpc_connected = False
43+
self.nodes[0].rpc = None
4044

4145
if __name__ == '__main__':
4246
HelpTest().main()

test/functional/test_framework/test_framework.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def main(self):
148148
if self.nodes:
149149
self.stop_nodes()
150150
else:
151+
for node in self.nodes:
152+
node.cleanup_on_exit = False
151153
self.log.info("Note: bitcoinds were not stopped and may still be running")
152154

153155
if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED:

test/functional/test_framework/test_node.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,20 @@ def __init__(self, i, datadir, rpchost, timewait, binary, stderr, mocktime, cove
8888
self.rpc = None
8989
self.url = None
9090
self.log = logging.getLogger('TestFramework.node%d' % i)
91+
self.cleanup_on_exit = True # Whether to kill the node when this object goes away
9192

9293
self.p2ps = []
9394

95+
def __del__(self):
96+
# Ensure that we don't leave any bitcoind processes lying around after
97+
# the test ends
98+
if self.process and self.cleanup_on_exit:
99+
# Should only happen on test failure
100+
# Avoid using logger, as that may have already been shutdown when
101+
# this destructor is called.
102+
print("Cleaning up leftover process")
103+
self.process.kill()
104+
94105
def __getattr__(self, name):
95106
"""Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
96107
if self.use_cli:

0 commit comments

Comments
 (0)