[qa] Ensure bitcoind processes are cleaned up when tests end

This commit is contained in:
Suhas Daftuar 2018-04-06 10:53:35 -04:00
parent 1d540046fe
commit e36a0c0852
3 changed files with 17 additions and 0 deletions

View file

@ -36,7 +36,11 @@ class HelpTest(BitcoinTestFramework):
output = self.nodes[0].process.stdout.read() output = self.nodes[0].process.stdout.read()
assert b'version' in output assert b'version' in output
self.log.info("Version text received: {} (...)".format(output[0:60])) self.log.info("Version text received: {} (...)".format(output[0:60]))
# Clean up TestNode state
self.nodes[0].running = False self.nodes[0].running = False
self.nodes[0].process = None
self.nodes[0].rpc_connected = False
self.nodes[0].rpc = None
if __name__ == '__main__': if __name__ == '__main__':
HelpTest().main() HelpTest().main()

View file

@ -148,6 +148,8 @@ class BitcoinTestFramework():
if self.nodes: if self.nodes:
self.stop_nodes() self.stop_nodes()
else: else:
for node in self.nodes:
node.cleanup_on_exit = False
self.log.info("Note: bitcoinds were not stopped and may still be running") 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: if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED:

View file

@ -81,9 +81,20 @@ class TestNode():
self.rpc = None self.rpc = None
self.url = None self.url = None
self.log = logging.getLogger('TestFramework.node%d' % i) 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 = [] 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): def __getattr__(self, name):
"""Dispatches any unrecognised messages to the RPC connection or a CLI instance.""" """Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
if self.use_cli: if self.use_cli: