Stop subprocess tests timing out when the machine is busy - #191
Merged
Conversation
Two test helpers waited for a subprocess by handing the wait off to a shared background worker. That worker is taken from a pool everyone else is also using, and it stays occupied for as long as the subprocess runs. When the whole suite runs at once the pool fills up, the wait never gets a turn, and the test gives up on its own timer long after the subprocess has actually finished. The result was tests failing after a minute and a half on scripts that finish in fifteen milliseconds. Two of them took turns breaking the build on main today. Now the wait is driven by the notification the system already sends when a process ends, which occupies nothing.
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.
What this does
unit-testsonmainkeeps failing on subprocess tests that time out after 90 seconds running scripts that finish in about 15 milliseconds. Two different tests took turns breaking the build today, and re-running did not clear it.Nothing was actually hanging. The test helper handed the "wait for this subprocess" job to a shared background worker, and that worker stayed occupied for as long as the subprocess lived. The suite runs in parallel, so enough of these at once fills the shared pool, the waiting job never gets a turn, and the test gives up on its own timer long after the subprocess already exited.
The wait is now driven by the notification the system already sends when a process ends, which occupies nothing.
Summary
runProcesshelpers inprogramaTests/WorkspaceRemoteConnectionTests.swift(:17,:1473) previously didDispatchQueue.global(qos: .userInitiated).async { process.waitUntilExit(); exitSignal.signal() }, blocking a pooled worker for the child's entire lifetime.process.terminationHandler = { _ in exitSignal.signal() }, set beforerun(). Foundation delivers it on its own private queue and blocks no shared thread.terminate()on timeout, the 1s grace wait, both pipes read withreadDataToEndOfFile(), andprocess.terminationStatusas the returned status.runProcessinprogramaTests/TabManagerUnitTests.swift:90is deliberately untouched — it has no timeout and callswaitUntilExit()on the calling thread, so it cannot produce this failure.Evidence
testRemoteRelayMetadataCleanupScriptPreservesDifferentSocketAddrfails at exactly its 90s timeout. Running the identical script it invokes, with the same non-matchingsocket_addr, completes in 0.015s with the exact filesystem outcome the test asserts.runProcess-based test in this class.Test plan
xcodebuild -scheme programa-unit build-for-testingsucceedsunit-testspasses on this PRunit-testsstays green across several subsequentmainruns — this is the real check, since a single green run cannot distinguish a fix from a lucky scheduling outcomeWorth flagging separately, pre-existing and not addressed here: both helpers read the pipes only after the process exits, so a child producing more than the pipe buffer (~64KB) would deadlock. No current test produces that much output.