qa: Only allow calling TestNode.stop() after connecting

(Still tolerate calling it on a no longer (self.)running node, as in a node that has been queried for is_node_stopped() and modified state before returning True).

Tests should not attempt to use the non-functioning RPC interface to call stop() unless wait_for_connections() has succeeded.

No longer log and suppress http.client.CannotSendRequest as a consequence of stop()-RPC, as error conditions causing this knock-on issue are now guarded against before the call.
This commit is contained in:
Hodlinator 2025-02-13 09:18:24 +01:00
parent 6ad21b4c01
commit 9b24a403fa
No known key found for this signature in database

View File

@ -8,7 +8,6 @@ import contextlib
import decimal
import errno
from enum import Enum
import http.client
import json
import logging
import os
@ -307,10 +306,11 @@ class TestNode():
# overhead is trivial, and the added guarantees are worth
# the minimal performance cost.
self.log.debug("RPC successfully started")
# Set rpc_connected even if we are in use_cli mode so that we know we can call self.stop() if needed.
self.rpc_connected = True
if self.use_cli:
return
self.rpc = rpc
self.rpc_connected = True
self.url = self.rpc.rpc_url
return
except JSONRPCException as e:
@ -396,15 +396,15 @@ class TestNode():
"""Stop the node."""
if not self.running:
return
assert self.rpc_connected, self._node_msg(
"Should only call stop_node() on a running node after wait_for_rpc_connection() succeeded. "
f"Did you forget to call the latter after start()? Not connected to process: {self.process.pid}")
self.log.debug("Stopping node")
try:
# Do not use wait argument when testing older nodes, e.g. in wallet_backwards_compatibility.py
if self.version_is_at_least(180000):
self.stop(wait=wait)
else:
self.stop()
except http.client.CannotSendRequest:
self.log.exception("Unable to stop node.")
# If there are any running perf processes, stop them.
for profile_name in tuple(self.perf_subprocesses.keys()):