Skip to content

Commit e36a0c0

Browse files
committed
[qa] Ensure bitcoind processes are cleaned up when tests end
1 parent 1d54004 commit e36a0c0

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
@@ -81,9 +81,20 @@ def __init__(self, i, datadir, rpchost, timewait, binary, stderr, mocktime, cove
8181
self.rpc = None
8282
self.url = None
8383
self.log = logging.getLogger('TestFramework.node%d' % i)
84+
self.cleanup_on_exit = True # Whether to kill the node when this object goes away
8485

8586
self.p2ps = []
8687

88+
def __del__(self):
89+
# Ensure that we don't leave any bitcoind processes lying around after
90+
# the test ends
91+
if self.process and self.cleanup_on_exit:
92+
# Should only happen on test failure
93+
# Avoid using logger, as that may have already been shutdown when
94+
# this destructor is called.
95+
print("Cleaning up leftover process")
96+
self.process.kill()
97+
8798
def __getattr__(self, name):
8899
"""Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
89100
if self.use_cli:

0 commit comments

Comments
 (0)