1 #!/usr/bin/env python3
2 # Copyright (c) 2018-present The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test bitcoind shutdown."""
6 7 from test_framework.test_framework import BitcoinTestFramework
8 from test_framework.util import assert_equal
9 from threading import Thread
10 11 def test_long_call(node):
12 block = node.waitfornewblock()
13 assert_equal(block['height'], 0)
14 15 class ShutdownTest(BitcoinTestFramework):
16 17 def set_test_params(self):
18 self.setup_clean_chain = True
19 self.num_nodes = 1
20 21 def run_test(self):
22 node = self.nodes[0].create_new_rpc_connection()
23 # Force connection establishment by executing a dummy command.
24 node.getblockcount()
25 Thread(target=test_long_call, args=(node,)).start()
26 # Wait until the server is executing the above `waitfornewblock`.
27 self.wait_until(lambda: len(self.nodes[0].getrpcinfo()['active_commands']) == 2)
28 # Wait 1 second after requesting shutdown but not before the `stop` call
29 # finishes. This is to ensure event loop waits for current connections
30 # to close.
31 self.stop_node(0, wait=1000)
32 33 if __name__ == '__main__':
34 ShutdownTest(__file__).main()
35