test: stop tests waiting out real timeouts

Merged
TE
2mo ago
+386-85

Summary

Some app-host unit tests only finish when a production timeout, drain bound, poll interval or retry delay runs out. This change applies the #15329 approach to them. Each timeout is now injectable, the production default does not change, and the tests pass a short value. No assertion changes.

Durations below come from the last main CI shard logs. "Expected" assumes the rest of each test takes the same time as before.

TestBeforeWait removedExpected saving
CloudPrivateRouteSelectionTests: failed dual-stack probe15.36 sCloudHubConnector 15 s connect deadline, now 1 s via a new CloudMachineLinkManager init parameterabout 14 s
CloudLoopbackPortForwardTests: refused CONNECT closes the client15.06 sCloudPortForwardRelay 15 s handshake timeout, now 1 s (the seam already existed)about 14 s
LastSurfaceClosePreferenceTests (14 tests)29.0 s suitedrainMainQueue 1 s per call, now 0.1 sabout 25 s
WorkspaceCloseTabsContextMenuTests (6 tests)12.4 s suitethe sameabout 10 s
WorkspaceSSHFishProcessDrainTests: timeoutKillsChildThatIgnoresTermination6.02 stest-local process timeout, now 1 s instead of 5 sabout 4 s
WorkspaceSSHFishProcessDrainTests: inheritedWriterDoesNotHoldReturnUntilEOF2.01 stest-local 2 s pipe drain bound, now 0.5 sabout 1.5 s
TerminalUploadCommandTests: realProcessDoesNotHangOnBackgroundedChild4.03 sTerminalCustomUploadRunner 2 s drain bound on each of 2 pipes, now 0.5 sabout 3 s
testVMLayoutApplyOpenGivesUpWithTheManualCommand4.06 s1 s between 5 open attempts, via CMUX_VM_LAYOUT_OPEN_RETRY_DELAY_SECONDSabout 3.8 s
testVMWaitPollsStatusUntilReady3.74 s3 s vm.status poll, via CMUX_VM_WAIT_POLL_SECONDSabout 3.5 s
CloudOperationRecorderTests: placement receipts (2 cases)4.05 sCloudTelemetryUploader 2 s batch delay, now 50 msabout 3.9 s
forkCapabilityProbeTerminatesSetsidDescendantHoldingOutputPipe3.50 sAgentForkSupport 3 s probe output timeout, now 1 sabout 2 s
forkCapabilityProbeHardKillsSigtermIgnoringSetsidDescendantAfterTimedOutLeaderExits3.62 sthe sameabout 2 s

That adds up to roughly 87 s of app-host test time, spread over the 7 shards.

Why drainMainQueue was slow: a @MainActor Swift Testing body already runs inside a main-queue block, so the helper's DispatchQueue.main.async cannot run until the test returns. Every call therefore spun the run loop for its whole 1 s timeout. The helper now takes a timeout (default 1 s, so XCTest callers are unchanged), and these two Swift Testing suites spin for 0.1 s.

Left alone on purpose, because the wait is the behavior under test:

  • The 3 s negative window in "Concurrent opens share one route check".
  • The waitUntilBlocked stability windows in the SSH startup tests.
  • The 2 s discovery policy in SSHStartupManualReconnectTests.
  • Tests whose time is spent on work (layout, SFTP, search).

Testing

  • swiftc -parse passes on every changed file.
  • The app compile and the app-host test shards come from this PR's CI.
  • After CI, the new per-test durations will be checked against the table above in the shard logs.

Changelog

none

🤖 Generated with Claude Code


Summary by cubic

App-host unit tests no longer wait out production timeouts — each timeout is now injectable with the same production default, tests pass a short value, and no assertions change. The suites save roughly 87 seconds of test time across the shards.

Refactors

  • drainMainQueue takes a timeout; @MainActor Swift Testing bodies run inside a main queue block, so each call previously spun the run loop for a full second.
  • The cloud handshake and private-route tests pass an injectable clock and advance it past the deadline instead of shortening it; the SSH fish kill test waits for a readiness marker so startup does not spend the kill budget.
  • The CLI reads CMUX_VM_WAIT_POLL_SECONDS and CMUX_VM_LAYOUT_OPEN_RETRY_DELAY_SECONDS; non-finite and oversized overrides fall back to production values (the wait poll capped at the remaining deadline), and new tests assert both fallbacks and the resulting poll count.
  • TerminalCustomUploadRunner drain bounds, CloudTelemetryUploader batch delay, and AgentForkSupport probe output timeout are injectable; the fork probe tests pass 2s instead of the 3s default.
  • FileExplorerState takes an injected UserDefaults, and sidebar mode availability now routes through it; the minimal-mode visibility test keeps the file explorer hidden so delayed workspace-root discovery cannot invalidate the chrome bodies.

Summary by CodeRabbit

  • Bug Fixes

    • VM workspace retries and readiness checks honor valid timing settings while keeping waits within command deadlines.
    • Cloud private-route selection uses the configured connector when checking available routes.
    • Process output collection and pipe draining use bounded, configurable timeouts, helping commands finish when background processes keep output pipes open.
  • Improvements

    • Cloud telemetry batching supports configurable delays.
    • Custom sidebar selection and file explorer preferences use the selected settings store for availability and persistence.