2018-11-20 18:59:07 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-12-31 09:48:25 +01:00
|
|
|
# Copyright (c) 2018-2020 The Bitcoin Core developers
|
2018-11-20 18:59:07 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
"""Test bitcoind shutdown."""
|
|
|
|
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2020-08-17 17:50:47 +02:00
|
|
|
from test_framework.util import assert_equal, get_rpc_proxy
|
2018-11-20 18:59:07 +01:00
|
|
|
from threading import Thread
|
|
|
|
|
|
|
|
def test_long_call(node):
|
|
|
|
block = node.waitfornewblock()
|
|
|
|
assert_equal(block['height'], 0)
|
|
|
|
|
|
|
|
class ShutdownTest(BitcoinTestFramework):
|
|
|
|
|
|
|
|
def set_test_params(self):
|
|
|
|
self.setup_clean_chain = True
|
|
|
|
self.num_nodes = 1
|
2019-12-06 15:37:49 +01:00
|
|
|
self.supports_cli = False
|
2018-11-20 18:59:07 +01:00
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
node = get_rpc_proxy(self.nodes[0].url, 1, timeout=600, coveragedir=self.nodes[0].coverage_dir)
|
2018-12-14 12:27:21 +01:00
|
|
|
# Force connection establishment by executing a dummy command.
|
|
|
|
node.getblockcount()
|
2018-11-20 18:59:07 +01:00
|
|
|
Thread(target=test_long_call, args=(node,)).start()
|
2018-12-14 12:27:21 +01:00
|
|
|
# Wait until the server is executing the above `waitfornewblock`.
|
2020-08-17 17:50:47 +02:00
|
|
|
self.wait_until(lambda: len(self.nodes[0].getrpcinfo()['active_commands']) == 2)
|
2018-12-14 12:27:21 +01:00
|
|
|
# Wait 1 second after requesting shutdown but not before the `stop` call
|
|
|
|
# finishes. This is to ensure event loop waits for current connections
|
|
|
|
# to close.
|
2018-11-20 18:59:07 +01:00
|
|
|
self.stop_node(0, wait=1000)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
ShutdownTest().main()
|