Skip to content

Commit 6c26df0

Browse files
sdaftuarMarcoFalke
authored andcommitted
[qa] Ensure bitcoind processes are cleaned up when tests end
Github-Pull: #12904 Rebased-From: e36a0c0
1 parent df38b13 commit 6c26df0

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
@@ -145,6 +145,8 @@ def main(self):
145145
if self.nodes:
146146
self.stop_nodes()
147147
else:
148+
for node in self.nodes:
149+
node.cleanup_on_exit = False
148150
self.log.info("Note: bitcoinds were not stopped and may still be running")
149151

150152
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
@@ -70,9 +70,20 @@ def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mo
7070
self.rpc = None
7171
self.url = None
7272
self.log = logging.getLogger('TestFramework.node%d' % i)
73+
self.cleanup_on_exit = True # Whether to kill the node when this object goes away
7374

7475
self.p2ps = []
7576

77+
def __del__(self):
78+
# Ensure that we don't leave any bitcoind processes lying around after
79+
# the test ends
80+
if self.process and self.cleanup_on_exit:
81+
# Should only happen on test failure
82+
# Avoid using logger, as that may have already been shutdown when
83+
# this destructor is called.
84+
print("Cleaning up leftover process")
85+
self.process.kill()
86+
7687
def __getattr__(self, name):
7788
"""Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
7889
if self.use_cli:

0 commit comments

Comments
 (0)