mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-26 17:02:00 +02:00
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:
parent
6ad21b4c01
commit
9b24a403fa
@ -8,7 +8,6 @@ import contextlib
|
|||||||
import decimal
|
import decimal
|
||||||
import errno
|
import errno
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import http.client
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -307,10 +306,11 @@ class TestNode():
|
|||||||
# overhead is trivial, and the added guarantees are worth
|
# overhead is trivial, and the added guarantees are worth
|
||||||
# the minimal performance cost.
|
# the minimal performance cost.
|
||||||
self.log.debug("RPC successfully started")
|
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:
|
if self.use_cli:
|
||||||
return
|
return
|
||||||
self.rpc = rpc
|
self.rpc = rpc
|
||||||
self.rpc_connected = True
|
|
||||||
self.url = self.rpc.rpc_url
|
self.url = self.rpc.rpc_url
|
||||||
return
|
return
|
||||||
except JSONRPCException as e:
|
except JSONRPCException as e:
|
||||||
@ -396,15 +396,15 @@ class TestNode():
|
|||||||
"""Stop the node."""
|
"""Stop the node."""
|
||||||
if not self.running:
|
if not self.running:
|
||||||
return
|
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")
|
self.log.debug("Stopping node")
|
||||||
try:
|
# Do not use wait argument when testing older nodes, e.g. in wallet_backwards_compatibility.py
|
||||||
# Do not use wait argument when testing older nodes, e.g. in wallet_backwards_compatibility.py
|
if self.version_is_at_least(180000):
|
||||||
if self.version_is_at_least(180000):
|
self.stop(wait=wait)
|
||||||
self.stop(wait=wait)
|
else:
|
||||||
else:
|
self.stop()
|
||||||
self.stop()
|
|
||||||
except http.client.CannotSendRequest:
|
|
||||||
self.log.exception("Unable to stop node.")
|
|
||||||
|
|
||||||
# If there are any running perf processes, stop them.
|
# If there are any running perf processes, stop them.
|
||||||
for profile_name in tuple(self.perf_subprocesses.keys()):
|
for profile_name in tuple(self.perf_subprocesses.keys()):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user