|
17 | 17 | assert_equal,
|
18 | 18 | get_rpc_proxy,
|
19 | 19 | rpc_url,
|
| 20 | + wait_until, |
20 | 21 | )
|
21 | 22 | from .authproxy import JSONRPCException
|
22 | 23 |
|
| 24 | +BITCOIND_PROC_WAIT_TIMEOUT = 60 |
| 25 | + |
23 | 26 | class TestNode():
|
24 | 27 | """A class for representing a bitcoind node under test.
|
25 | 28 |
|
@@ -125,25 +128,28 @@ def is_node_stopped(self):
|
125 | 128 | if not self.running:
|
126 | 129 | return True
|
127 | 130 | 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) |
136 | 145 |
|
137 | 146 | def node_encrypt_wallet(self, passphrase):
|
138 | 147 | """"Encrypts the wallet.
|
139 | 148 |
|
140 | 149 | This causes bitcoind to shutdown, so this method takes
|
141 | 150 | care of cleaning up resources."""
|
142 | 151 | 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() |
147 | 153 |
|
148 | 154 | class TestNodeCLI():
|
149 | 155 | """Interface to bitcoin-cli for an individual node"""
|
|
0 commit comments