Skip to content

Keep socket test waits off the main thread - #1016

Merged
onevcat merged 1 commit into
mainfrom
fix/cli-socket-test-main-thread-wait
Oct 31, 2026
Merged

onevcat merged 1 commit into
mainfrom
fix/cli-socket-test-main-thread-wait

Conversation

@onevcat

@onevcat onevcat commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Problem

CLISocketServerTests/nativeHookRoutesAfterPeerClosesBeforeMainActorHandling() failed on CI with Expectation failed: didRoute (run). This is a test defect, not a product defect.

TestStore installs a process-global hook that runs Task.detached on the main thread. The test blocked on a semaphore inside such a task. When routing lost the race, the blocked main thread stopped the main-actor work that the semaphore waited for, and the wait used its full 10 s timeout.

Two more tests wait on main-actor work in the same way:

  • descriptorDuplicationFailureRejectsConnectionBeforeRouting()
  • closingPeerCancelsInFlightWaitRequest()

Fix

Add a runBlocking helper that runs blocking work on a dispatch queue, and use it for all blocking waits and sends in CLISocketServerTests. A longer timeout cannot fix this: the main thread stays blocked for the full wait.

Only App/Tests/CLISocketServerTests.swift changes.

Verification

To force the race, I temporarily turned the hook on and added a 50 ms delay on the accept queue after peerClosed.signal(). These edits are not in this PR.

Three tests above
Before the fix all failed
After the fix all passed, about 0.06 s each

make check, make test, and make build-app pass with the final code.

TestStore installs a process-global hook that runs Task.detached on the
main thread. A blocking wait inside such a task stopped the main-actor
work it waited for, so the wait timed out when routing lost the race.
Run the blocking work in CLISocketServerTests on a dispatch queue.
@onevcat
onevcat merged commit 7cb398f into main Oct 31, 2026
1 check passed
@onevcat
onevcat deleted the fix/cli-socket-test-main-thread-wait branch October 31, 2026 13:27
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.

1 participant