Skip to content

tests: fix websocket connect races in test_clnrest - #9581

Open
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:fix-test_websocket_no_rune
Open

daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:fix-test_websocket_no_rune

Conversation

@daywalker90

Copy link
Copy Markdown
Collaborator

notifications_received_via_websocket() relied on the socketio client's connect_error callback and its default 1s wait_timeout to detect the namespace handshake result. Under CI load the namespace CONNECT reply is sometimes lost during the polling to websocket upgrade, so sio.connect() raises

socketio.exceptions.ConnectionError: One or more namespaces failed to
connect:

even though the server logged "Authorized rune" and "Socket.IO connected". The connect_error callback therefore never fired, so for the rejection tests the test compared the expected error against an empty string, e.g.

ValueError: Expected error code Missing rune, got One or more namespaces failed to connect: instead

This affected both the rejection tests (test_websocket_no_rune, test_websocket_wrong_rune, test_websocket_rune_no_listnotifications, test_websocket_upgrade_header) and the successful-connection tests (test_websocket_unrestricted_rune, test_websocket_rune_readonly, test_websocket_rune_listnotifications, test_numeric_msat_notification).

Give the namespace handshake a longer timeout, disable the client's background reconnection and retry transient connect failures for the success path. Check the node log for the expected rejection instead of the unreliable client-side error text.

Changelog-None

Fixes: #9561

Andezion
Andezion previously approved these changes Sep 30, 2026

@Andezion Andezion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a trace or log showing that the CONNECT packet was really lost, and not just late? Also should we keep a client side check of the error text when connect_error does fire, so we dont lose coverage?

Comment thread tests/test_clnrest.py Outdated
@daywalker90

Copy link
Copy Markdown
Collaborator Author

I could not find a log for a lost case but this should cover both lost and late.

@daywalker90

Copy link
Copy Markdown
Collaborator Author

Added the error message coverage back in.

Andezion
Andezion previously approved these changes Sep 30, 2026
Comment thread tests/test_clnrest.py
notifications_received_via_websocket() relied on the socketio client's
connect_error callback and its default 1s wait_timeout to detect the
namespace handshake result.  In the flakes the server logged
"Authorized rune" and "Socket.IO connected" well inside that window, yet
the client raised

  socketio.exceptions.ConnectionError: One or more namespaces failed to
  connect:

so the connect_error callback never fired and, for the rejection tests,
the expected error was compared against an empty string, e.g.

  ValueError: Expected error code `Missing rune`, got `One or more
  namespaces failed to connect: ` instead

Why the client does not process the server's namespace reply is not
established: it could not be reproduced locally, and the engine.io
upgrade path on both sides looks correct.  So this works around it rather
than fixing a root cause.

This affected both the rejection tests (test_websocket_no_rune,
test_websocket_wrong_rune, test_websocket_rune_no_listnotifications,
test_websocket_upgrade_header) and the successful-connection tests
(test_websocket_unrestricted_rune, test_websocket_rune_readonly,
test_websocket_rune_listnotifications, test_numeric_msat_notification).

Give the namespace handshake a longer timeout, disable the client's
background reconnection and retry transient connect failures for the
success path.  Keep checking the exact text the server sent when the
connect_error callback fires, and fall back to the node log when it does
not.  Also make test_websocket_upgrade_header fail if the connection
unexpectedly succeeds, instead of falling through.

Changelog-None

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI flake test_websocket_no_rune

2 participants