Skip to content

Commit 9b24a40

Browse files
committed
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.
1 parent 6ad21b4 commit 9b24a40

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

test/functional/test_framework/test_node.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import decimal
99
import errno
1010
from enum import Enum
11-
import http.client
1211
import json
1312
import logging
1413
import os
@@ -307,10 +306,11 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
307306
# overhead is trivial, and the added guarantees are worth
308307
# the minimal performance cost.
309308
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
310311
if self.use_cli:
311312
return
312313
self.rpc = rpc
313-
self.rpc_connected = True
314314
self.url = self.rpc.rpc_url
315315
return
316316
except JSONRPCException as e:
@@ -396,15 +396,15 @@ def stop_node(self, expected_stderr='', *, wait=0, wait_until_stopped=True):
396396
"""Stop the node."""
397397
if not self.running:
398398
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}")
399402
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()
408408

409409
# If there are any running perf processes, stop them.
410410
for profile_name in tuple(self.perf_subprocesses.keys()):

0 commit comments

Comments
 (0)