Skip to content

test(zero-swift): make the lifecycle tests' process connect once before the first test - #285

Merged
tmm merged 1 commit into
mainfrom
swift-lifecycle-first-connect
Dec 1, 2026
Merged

tmm merged 1 commit into
mainfrom
swift-lifecycle-first-connect

Conversation

@tmm

@tmm tmm commented Dec 1, 2026

Copy link
Copy Markdown
Member

Fixes the recurring AppLifecycleTests.hiddenDisconnectsAndShownReconnects (and once hiddenWhileConnecting) flake in the iOS Simulator step of Swift end-to-end (macOS), which failed on #274, #282 and #283. Test-only, so no changeset.

Cause

The step runs while the simulator's first boot keeps the 3-core runner's load average at 150–470 for minutes. Before a process's first URLSession connect opens its socket, it waits on one-time setup in system services: cfprefsd, containermanagerd, the runningboardd handshake, and configd_sim's proxy lookup. On CI that took from about 1 s to about 30 s, and the 3 failures since #235 (3 of 48 runs) were all this first connect running past the test's 12.5 s connectWait. The process's later connects don't wait for it: the second test took 0.15–0.25 s in 37 of 38 probe runs.

It is not a client bug, and the test's loopback server isn't involved: the time goes to system services before the socket exists. It also isn't what #235 fixed; that step already runs with OS_ACTIVITY_MODE=disable.

Evidence:

  • The simulator's unified log and CPU samples from probe runs of this job on macos-26 show the wait.
  • On a Mac, stopping the simulator's configd_sim as the test process starts reproduces the CI failure line for line, and a sample shows the connect blocked in SCDynamicStoreCopyProxies.

These didn't remove the stall on CI, which is why the fix is in the test:

Tried Runs First iOS test over 1 s Slowest
As today 9 3 3.1 s
Wait for simctl bootstatus -b first 6 2 7.0 s
zero-cache and Postgres stopped first 8 1 4.1 s
A job of its own on a fresh runner 12 1 1.2 s
An explicit empty proxy dictionary (Mac, configd_sim stopped) fails as before

Fix

AppLifecycleTests makes the process's first connect once, to a loopback server of its own, before its first test, and logs how long it took. The tests' waits start after it, and every test keeps its current wait limits. URLSession's request timeout (60 s) bounds the warm-up, within the first test's 2-minute limit. If it fails, every test fails at once with its error.

Verification

  • Mac satellite, iOS 26.2 Simulator, configd_sim stopped for the first 30 s of the test process: main failed 3 of 3 (first test at 12.5 s, as on CI). This branch passed 3 of 3 (warm-up about 29.8 s) and also passed with a 45 s stop.
  • Same Mac, without a stop: both pass 3 of 3, with a 13 ms warm-up.
  • A 75 s stop: the warm-up times out at 60 s and every test reports The request timed out.
  • macOS: swift test --filter AppLifecycleTests passes with a 16 ms warm-up, and swift format lint --strict passes.
  • 8 runs of this job on this commit (run): all passed. The iOS warm-up took 0.05–0.29 s and the first test 0.19–1.05 s. None of those runners hit the long stall, which shows up in about 6% of runs, so the configd_sim test above is the one that exercises the fix.

…re the first test

AppLifecycleTests.hiddenDisconnectsAndShownReconnects (and once
hiddenWhileConnecting) failed in the iOS Simulator step of "Swift end-to-end
(macOS)": the first connect never reached the test's server within
connectWait. On CI the step runs while the simulator's first boot keeps the
3-core runner's load average at 150-470 for minutes. A process's first
URLSession connect waits, before its socket opens, on what the system's
services (cfprefsd, containermanagerd, runningboardd, configd_sim) set up once
per process, and the simulator's unified log on CI showed that taking from
about a second to about 30 s. The process's later connects don't wait for it:
the second test took 0.15-0.25 s in 37 of 38 probe runs. Waiting for the
simulator's boot to finish, stopping zero-cache and Postgres, or a job of its
own didn't take the first connect's delay away.

The suite now makes the process's first connect once, before its first test,
and the tests' waits start after it. URLSession's request timeout (60 s) bounds
it, within the first test's 2-minute time limit. Stopping the simulator's
configd_sim for the first 30 s of the test process failed main 3 of 3 times
(the first test at 12.5 s) and passes now 3 of 3, with a 45 s stop too.

Amp-Thread-ID: https://ampcode.com/threads/T-01a22e8b-3956-7364-87ad-1c52739ad938
Co-authored-by: tmm <tmm@tmm.dev>
@tmm
tmm merged commit 7e759c1 into main Dec 1, 2026
22 checks passed
@tmm
tmm deleted the swift-lifecycle-first-connect branch December 1, 2026 07:58
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.

2 participants