Skip to content

Commit faa8d95

Browse files
author
MarcoFalke
committed
[qa] TestNode: Add wait_until_stopped helper method
1 parent 777519b commit faa8d95

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

test/functional/blockchain.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import http.client
2222
import subprocess
2323

24-
from test_framework.test_framework import (BitcoinTestFramework, BITCOIND_PROC_WAIT_TIMEOUT)
24+
from test_framework.test_framework import BitcoinTestFramework
2525
from test_framework.util import (
2626
assert_equal,
2727
assert_raises,
@@ -141,7 +141,7 @@ def _test_stopatheight(self):
141141
except (ConnectionError, http.client.BadStatusLine):
142142
pass # The node already shut down before response
143143
self.log.debug('Node should stop at this height...')
144-
self.nodes[0].process.wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
144+
self.nodes[0].wait_until_stopped()
145145
self.start_node(0)
146146
assert_equal(self.nodes[0].getblockcount(), 207)
147147

test/functional/fundrawtransaction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the fundrawtransaction RPC."""
66

7-
from test_framework.test_framework import BitcoinTestFramework, BITCOIND_PROC_WAIT_TIMEOUT
7+
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import *
99

1010

test/functional/test_framework/test_framework.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ class TestStatus(Enum):
4343
TEST_EXIT_FAILED = 1
4444
TEST_EXIT_SKIPPED = 77
4545

46-
BITCOIND_PROC_WAIT_TIMEOUT = 60
47-
4846
class BitcoinTestFramework(object):
4947
"""Base class for a bitcoin test script.
5048
@@ -263,8 +261,7 @@ def start_nodes(self, extra_args=None):
263261
def stop_node(self, i):
264262
"""Stop a bitcoind test node"""
265263
self.nodes[i].stop_node()
266-
while not self.nodes[i].is_node_stopped():
267-
time.sleep(0.1)
264+
self.nodes[i].wait_until_stopped()
268265

269266
def stop_nodes(self):
270267
"""Stop multiple bitcoind test nodes"""
@@ -274,8 +271,7 @@ def stop_nodes(self):
274271

275272
for node in self.nodes:
276273
# Wait for nodes to stop
277-
while not node.is_node_stopped():
278-
time.sleep(0.1)
274+
node.wait_until_stopped()
279275

280276
def assert_start_raises_init_error(self, i, extra_args=None, expected_msg=None):
281277
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:

test/functional/test_framework/test_node.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
assert_equal,
1818
get_rpc_proxy,
1919
rpc_url,
20+
wait_until,
2021
)
2122
from .authproxy import JSONRPCException
2223

24+
BITCOIND_PROC_WAIT_TIMEOUT = 60
25+
2326
class TestNode():
2427
"""A class for representing a bitcoind node under test.
2528
@@ -125,25 +128,28 @@ def is_node_stopped(self):
125128
if not self.running:
126129
return True
127130
return_code = self.process.poll()
128-
if return_code is not None:
129-
# process has stopped. Assert that it didn't return an error code.
130-
assert_equal(return_code, 0)
131-
self.running = False
132-
self.process = None
133-
self.log.debug("Node stopped")
134-
return True
135-
return False
131+
if return_code is None:
132+
return False
133+
134+
# process has stopped. Assert that it didn't return an error code.
135+
assert_equal(return_code, 0)
136+
self.running = False
137+
self.process = None
138+
self.rpc_connected = False
139+
self.rpc = None
140+
self.log.debug("Node stopped")
141+
return True
142+
143+
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
144+
wait_until(self.is_node_stopped, timeout=timeout)
136145

137146
def node_encrypt_wallet(self, passphrase):
138147
""""Encrypts the wallet.
139148
140149
This causes bitcoind to shutdown, so this method takes
141150
care of cleaning up resources."""
142151
self.encryptwallet(passphrase)
143-
while not self.is_node_stopped():
144-
time.sleep(0.1)
145-
self.rpc = None
146-
self.rpc_connected = False
152+
self.wait_until_stopped()
147153

148154
class TestNodeCLI():
149155
"""Interface to bitcoin-cli for an individual node"""

test/functional/wallet-encryption.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import time
88

9-
from test_framework.test_framework import BitcoinTestFramework, BITCOIND_PROC_WAIT_TIMEOUT
9+
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import (
1111
assert_equal,
1212
assert_raises_jsonrpc,

0 commit comments

Comments
 (0)