Skip to content

Commit 28479f9

Browse files
committed
qa: Test bitcond shutdown
1 parent 8d3f46e commit 28479f9

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

test/functional/feature_shutdown.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 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, get_rpc_proxy
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 = get_rpc_proxy(self.nodes[0].url, 1, timeout=600, coveragedir=self.nodes[0].coverage_dir)
23+
Thread(target=test_long_call, args=(node,)).start()
24+
# wait 1 second to ensure event loop waits for current connections to close
25+
self.stop_node(0, wait=1000)
26+
27+
if __name__ == '__main__':
28+
ShutdownTest().main()

test/functional/test_framework/test_framework.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,16 @@ def start_nodes(self, extra_args=None, *args, **kwargs):
325325
for node in self.nodes:
326326
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
327327

328-
def stop_node(self, i, expected_stderr=''):
328+
def stop_node(self, i, expected_stderr='', wait=0):
329329
"""Stop a bitcoind test node"""
330-
self.nodes[i].stop_node(expected_stderr)
330+
self.nodes[i].stop_node(expected_stderr, wait=wait)
331331
self.nodes[i].wait_until_stopped()
332332

333-
def stop_nodes(self):
333+
def stop_nodes(self, wait=0):
334334
"""Stop multiple bitcoind test nodes"""
335335
for node in self.nodes:
336336
# Issue RPC to stop nodes
337-
node.stop_node()
337+
node.stop_node(wait=wait)
338338

339339
for node in self.nodes:
340340
# Wait for nodes to stop

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ def get_wallet_rpc(self, wallet_name):
228228
wallet_path = "wallet/{}".format(urllib.parse.quote(wallet_name))
229229
return self.rpc / wallet_path
230230

231-
def stop_node(self, expected_stderr=''):
231+
def stop_node(self, expected_stderr='', wait=0):
232232
"""Stop the node."""
233233
if not self.running:
234234
return
235235
self.log.debug("Stopping node")
236236
try:
237-
self.stop()
237+
self.stop(wait=wait)
238238
except http.client.CannotSendRequest:
239239
self.log.exception("Unable to stop node.")
240240

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
'feature_config_args.py',
186186
'rpc_help.py',
187187
'feature_help.py',
188+
'feature_shutdown.py',
188189
# Don't append tests at the end to avoid merge conflicts
189190
# Put them in a random line within the section that fits their approximate run-time
190191
]

0 commit comments

Comments
 (0)