Repository navigation
test(gateway): stale-recovery health test can read the loopback server's accepted count before it records the new socket - #2211
Merged
Conversation
…r's accepted count before it records the new socket OpenClawGatewayClientTests.CheckHealth_StaleRecoveryCannotReplaceNewerSocket (added in openclaw#2079, "transport loss fails pending requests") failed once on main with "Expected: 2, Actual: 1" at its accepted-socket count. The product held: the newer socket was open, its generation and session key were unchanged, and no reconnect was authorized. The loopback test server records a socket only after AcceptWebSocketAsync has sent 101, on a thread-pool continuation, so the client's ConnectAsync can return before the count includes it. - Wait for the expected count with the server's existing WaitForAcceptedCountAsync (bounded by the named StepTimeout), as the file's other accepted-count checks do, then keep the exact-count assertion so an extra stale-recovery socket still fails. Co-authored-by: Copilot App <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #2079
What Problem This Solves
Fixes: the Core test job fails the gateway stale-recovery health test when it reads the loopback server's accepted-socket count before the server has recorded the new connection.
User Impact
User impact: no user-visible change. The Core test job no longer needs a rerun for this test. Gateway reconnect and health behavior are unchanged.
Why This Change Was Made
OpenClawGatewayClientTests.CheckHealth_StaleRecoveryCannotReplaceNewerSocket(delayedSend: True)failed once onmainefb2442c(run 43539494326, job 132276558851), after 49 ms. The failure was "Assert.Equal() Failure: Expected: 2, Actual: 1" at the server's accepted-socket count. This test was added in #2079 (transport loss fails pending requests), and this change keeps it as is apart from one wait.This is not a product race. Every assertion about the product passed before the count check:
agent:new:main).A stale recovery replacing the newer socket would cause more sockets or a different generation, not fewer.
The test server counts sockets late.
LoopbackWebSocketServeradds a socket to its list only afterAcceptWebSocketAsynchas already sent the101 Switching Protocolsreply, in a continuation on the shared thread pool. The client'sConnectAsyncreturns as soon as it receives101, so the test could read the count before the server had recorded the second socket.Change (test only, two lines): before the exact-count assertion, the test waits for the expected count with the server's existing
WaitForAcceptedCountAsync. The wait is bounded by the file's namedStepTimeout(OPENCLAW_TEST_GATEWAY_STEP_TIMEOUT_SECONDS), as the file's other accepted-count checks already do. The exact-count assertion is kept, so an extra stale-recovery socket still fails the test.Evidence
Harness: a scratch build (not committed) makes the test server record each socket 300 ms after sending
101.CheckHealth_StaleRecoveryCannotReplaceNewerSocketwith the slow serverdelayedSend: Truefailed 3/3 with exactlyExpected: 2, Actual: 1On the real test server, both cases passed 50 runs: 100/100.
Review:
claude-opus-5.5(high) andgpt-6-astra(long_context, high). Neither found an actionable issue.ConnectAsyncalways opens a new socket.delayedSend: Falsehas the same ordering gap, though it rarely shows.Change Type
Scope
winnodeRequired proof pools
none: test-only change to one unit-test assertion. Product code, UI, MCP, Gateway andsystem.runare unchanged.Validation
On head
0e48120e(rebased ontob713f345, whose only change is in an unrelated UI test):CheckHealth_*cases, 10 runs: 20/20 passed.On the same change before the rebase (base
7051c986):./build.ps1: passed.dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj: 5876 passed, 29 skipped, 0 failed.dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj(isolated profile): 6668 passed, 0 failed.CheckHealth_StaleRecoveryCannotReplaceNewerSocket, 50 runs: 100/100 passed../scripts/validate-test-timing-patterns.ps1andgit diff --check: passed.Real Behavior Proof
0e48120e. The harness and the full suites ran on the same change before the rebase.Passed! - Failed: 0, Passed: 2for both cases with the slow server. The original showedFailed ... CheckHealth_StaleRecoveryCannotReplaceNewerSocket(delayedSend: True) ... Expected: 2 Actual: 1.Yes/No/N/A): N/A (unit test; output is quoted above).Security Impact
Yes/No): NoYes/No): NoYes/No): NoYes/No): NoYes/No): NoYes, explain the risk and mitigation: N/ACompatibility and Migration
Yes/No): YesYes/No): No.Yes/No): NoReview Conversations