|
8 | 8 | import decimal
|
9 | 9 | import errno
|
10 | 10 | from enum import Enum
|
11 |
| -import http.client |
12 | 11 | import json
|
13 | 12 | import logging
|
14 | 13 | import os
|
@@ -307,10 +306,11 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
|
307 | 306 | # overhead is trivial, and the added guarantees are worth
|
308 | 307 | # the minimal performance cost.
|
309 | 308 | self.log.debug("RPC successfully started")
|
| 309 | + # Set rpc_connected even if we are in use_cli mode so that we know we can call self.stop() if needed. |
| 310 | + self.rpc_connected = True |
310 | 311 | if self.use_cli:
|
311 | 312 | return
|
312 | 313 | self.rpc = rpc
|
313 |
| - self.rpc_connected = True |
314 | 314 | self.url = self.rpc.rpc_url
|
315 | 315 | return
|
316 | 316 | except JSONRPCException as e:
|
@@ -396,15 +396,15 @@ def stop_node(self, expected_stderr='', *, wait=0, wait_until_stopped=True):
|
396 | 396 | """Stop the node."""
|
397 | 397 | if not self.running:
|
398 | 398 | return
|
| 399 | + assert self.rpc_connected, self._node_msg( |
| 400 | + "Should only call stop_node() on a running node after wait_for_rpc_connection() succeeded. " |
| 401 | + f"Did you forget to call the latter after start()? Not connected to process: {self.process.pid}") |
399 | 402 | self.log.debug("Stopping node")
|
400 |
| - try: |
401 |
| - # Do not use wait argument when testing older nodes, e.g. in wallet_backwards_compatibility.py |
402 |
| - if self.version_is_at_least(180000): |
403 |
| - self.stop(wait=wait) |
404 |
| - else: |
405 |
| - self.stop() |
406 |
| - except http.client.CannotSendRequest: |
407 |
| - self.log.exception("Unable to stop node.") |
| 403 | + # Do not use wait argument when testing older nodes, e.g. in wallet_backwards_compatibility.py |
| 404 | + if self.version_is_at_least(180000): |
| 405 | + self.stop(wait=wait) |
| 406 | + else: |
| 407 | + self.stop() |
408 | 408 |
|
409 | 409 | # If there are any running perf processes, stop them.
|
410 | 410 | for profile_name in tuple(self.perf_subprocesses.keys()):
|
|
0 commit comments