From e36a0c08529bccc695ec71a7ec1df89367cc1628 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Fri, 6 Apr 2018 10:53:35 -0400 Subject: [PATCH] [qa] Ensure bitcoind processes are cleaned up when tests end --- test/functional/feature_help.py | 4 ++++ test/functional/test_framework/test_framework.py | 2 ++ test/functional/test_framework/test_node.py | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/test/functional/feature_help.py b/test/functional/feature_help.py index 1e62d7a4092..fd4a72f628f 100755 --- a/test/functional/feature_help.py +++ b/test/functional/feature_help.py @@ -36,7 +36,11 @@ class HelpTest(BitcoinTestFramework): output = self.nodes[0].process.stdout.read() assert b'version' in output self.log.info("Version text received: {} (...)".format(output[0:60])) + # Clean up TestNode state self.nodes[0].running = False + self.nodes[0].process = None + self.nodes[0].rpc_connected = False + self.nodes[0].rpc = None if __name__ == '__main__': HelpTest().main() diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index d427f62856f..1a71796e91f 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -148,6 +148,8 @@ class BitcoinTestFramework(): if self.nodes: self.stop_nodes() else: + for node in self.nodes: + node.cleanup_on_exit = False self.log.info("Note: bitcoinds were not stopped and may still be running") if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED: diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 291ac3ee46c..b3c2fc0a09b 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -81,9 +81,20 @@ class TestNode(): self.rpc = None self.url = None self.log = logging.getLogger('TestFramework.node%d' % i) + self.cleanup_on_exit = True # Whether to kill the node when this object goes away self.p2ps = [] + def __del__(self): + # Ensure that we don't leave any bitcoind processes lying around after + # the test ends + if self.process and self.cleanup_on_exit: + # Should only happen on test failure + # Avoid using logger, as that may have already been shutdown when + # this destructor is called. + print("Cleaning up leftover process") + self.process.kill() + def __getattr__(self, name): """Dispatches any unrecognised messages to the RPC connection or a CLI instance.""" if self.use_cli: