Skip to content

Commit 879243e

Browse files
committed
qa refactor: wait_for_rpc_connection - Treat OSErrors the same
ConnectionResetError is an OSError as well (ECONNRESET), no reason to have a separate except-block for it. Also improves comments for other exceptions and make condition above more Pythonic.
1 parent d91a746 commit 879243e

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

test/functional/test_framework/test_node.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -311,23 +311,23 @@ def wait_for_rpc_connection(self, *, wait_for_import=True):
311311
self.rpc_connected = True
312312
self.url = self.rpc.rpc_url
313313
return
314-
except JSONRPCException as e: # Initialization phase
314+
except JSONRPCException as e:
315+
# Suppress these as they are expected during initialization.
315316
# -28 RPC in warmup
316-
# -342 Service unavailable, RPC server started but is shutting down due to error
317-
if e.error['code'] != -28 and e.error['code'] != -342:
317+
# -342 Service unavailable, could be starting up or shutting down
318+
if e.error['code'] not in [-28, -342]:
318319
raise # unknown JSON RPC exception
319-
except ConnectionResetError:
320-
# This might happen when the RPC server is in warmup, but shut down before the call to getblockcount
321-
# succeeds. Try again to properly raise the FailedToStartError
322-
pass
323320
except OSError as e:
324-
if e.errno == errno.ETIMEDOUT:
325-
pass # Treat identical to ConnectionResetError
326-
elif e.errno == errno.ECONNREFUSED:
327-
pass # Port not yet open?
328-
else:
321+
# Suppress similarly to the above JSONRPCException errors.
322+
if e.errno not in [
323+
errno.ECONNRESET, # This might happen when the RPC server is in warmup,
324+
# but shut down before the call to getblockcount succeeds.
325+
errno.ETIMEDOUT, # Treat identical to ECONNRESET
326+
errno.ECONNREFUSED # Port not yet open?
327+
]:
329328
raise # unknown OS error
330-
except ValueError as e: # cookie file not found and no rpcuser or rpcpassword; bitcoind is still starting
329+
except ValueError as e:
330+
# Suppress if cookie file isn't generated yet and no rpcuser or rpcpassword; bitcoind may be starting.
331331
if "No RPC credentials" not in str(e):
332332
raise
333333
time.sleep(1.0 / poll_per_s)

0 commit comments

Comments
 (0)