Repository navigation
Run Thread Sanitizer on macOS, test on iOS 18, and run each test once - #99
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude/2.0-11-actor-queue-priority #99 +/- ##
====================================================================
Coverage 100.00% 100.00%
====================================================================
Files 15 15
Lines 3294 3290 -4
====================================================================
- Hits 3294 3290 -4
🚀 New features to boost your workflow:
|
0b56c95 to
3b06141
Compare
3b06141 to
6bf50d5
Compare
|
Build Xcode (visionOS) failed on State 1 is "Booting". The log has no test output, so this commit's code never ran on visionOS. Every other job on this commit has passed, including iOS/watchOS, macOS/tvOS and Thread Sanitizer on macOS; Build Xcode Minimum iOS is still queued. The new upload step worked: it saved Generated by Claude Code |
|
Correction: the CodeQL Swift failure I reported here is fixed by Generated by Claude Code |
No CI job ran Thread Sanitizer. On Linux it flags `Synchronization.Mutex` even in correct code, so a Linux job would fail on every run. A new job on the xcode-27 runner builds the tests with Thread Sanitizer and runs them on macOS instead. When Thread Sanitizer reports a data race, the test run exits with an error and the job fails. In three trial runs on GitHub's runners the job took about a minute and a half and reported nothing. Like the other jobs that run the tests outside a simulator, it stops after 15 minutes so that a deadlocked test can't hold the runner for GitHub's six-hour default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
The package supports iOS 18, but CI tested only on the iOS 27.2 simulator. Before iOS 26, a queue's tasks wait for their turns without escalating priority. Tests reached that path in `Turns` only through `Turns(escalatesPriority: false)`, and no queue's tests ran on it. Xcode 27 can't download the iOS 18 simulator runtime: `xcodebuild -downloadPlatform iOS -buildVersion 22F77` fails with "iOS 22F77 is not available for download". The `macos-15` runner has iOS 18.5 installed as a disk image, so a new job there copies the image and uploads it as an artifact. Exporting the runtime with `xcodebuild -downloadPlatform -exportPath` instead fails at random with "Unable to connect to simulator." A second job, on the `xcode-27` runner, downloads the image and installs it. Adding the 9 GB image to the runner's simulator runtimes fails with "Cannot copy the image because the disk is almost full", so it first deletes every runtime but the 27.2 runtime of each platform. It then creates an iPad (10th generation) on iOS 18.5, and runs and uploads coverage for the tests there with Xcode 27.2, like the other simulator jobs. Tests that need iOS 26 are skipped. The two scripts in Scripts/ explain each step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
The simulator jobs ran the suite up to 100 times and stopped at the first failure, so that a test which fails only on some interleavings had more chances to fail. Every test should instead give the same result on every run: pass every run on correct code, and fail every run, or hang until the job's timeout, on the regression it guards. The simulator jobs now run the suite once, which also makes them shorter. A new CLAUDE.md records that rule for people and agents working on the package: force interleavings with semaphores, manual executors, and test hooks, never with sleeps, wall-clock timeouts, polling, or repetition. It names the few older loop tests that stay as backstops until a deterministic test fails 10 of 10 runs for every bug each catches. It also records the package's other rules: 100% code coverage; never cancel, resume, or escalate a task while holding a lock, including the runtime's own lock on a task while it runs the task's handlers; faster code over shorter code on the path that enqueues a task; `guard` but no early return from an `if` without an `else`; and documentation in the plain style of The Swift Programming Language. Those loop tests now get one run per simulator job instead of up to 100, so they are less likely to catch a rare bad interleaving there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
ManualTaskExecutor and ManualSerialExecutor ran their jobs inside `DispatchQueue.sync` on a private serial queue, which only serialized calls to `runUntilIdle()`. No test needs that. Each test makes its own executors, and calls `runUntilIdle()` from its own task, one call after another. No job calls `runUntilIdle()` on the executor that runs it. So run the jobs directly on the calling thread, as `DispatchQueue.sync` already did, and say in the documentation comments that a test calls `runUntilIdle()` from one task at a time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
A test process that crashes, such as one in a simulator, fails the job without saying why in the log. When the Xcode jobs fail, upload the result bundles that xcodebuild writes under .build/derivedData and the crash reports in ~/Library/Logs/DiagnosticReports. When the macOS swift test jobs fail, upload the crash reports. The artifacts expire after 7 days. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM
6bf50d5 to
2bf44ae
Compare
Summary
This PR adds two kinds of CI coverage, changes how often the simulator jobs run the tests, and removes the last
DispatchQueueused as a lock, in the tests' manual executors. It also keeps test results and crash reports when a test job fails.Run Thread Sanitizer on macOS. No CI job ran Thread Sanitizer. On Linux it flags
Synchronization.Mutexwhenever two threads contend for it, because it can't see the lock's slow path in the prebuilt standard library, so a Linux job would fail on most runs: 8 of 9 trial runs reported races, all in code thatMutexguards. A new job, "Thread Sanitizer on macOS", builds the tests with--sanitize=threadon thexcode-27runner with Xcode 27.2 and runs them. Thread Sanitizer makes the process exit with an error when it reports a data race, so a race fails the job. In three trial runs it took about 1.5 minutes and reported nothing. Like the other jobs that run tests outside a simulator, it stops after 15 minutes.Test on the iOS 18 simulator. The package supports iOS 18, but CI tested only on iOS 27.2. Two new jobs test on iOS 18.5 with Xcode 27.2:
macos-15, which has iOS 18.5 (build 22F77) installed as a disk image.Scripts/copy-ios-18-simulator.shfinds the image withxcrun simctl runtime list -jand copies it. The job uploads it as an artifact of about 9.1 GB, without compression and kept for one day.xcode-27once the first job is done. It downloads the image, andScripts/install-ios-18-simulator.shinstalls it and creates an iPad (10th generation) on iOS 18.5. A newiOS18platform inScripts/build.swiftthen runs the tests on that iPad, and the job uploads coverage like the other simulator jobs. Its derived data goes to.build/derivedData/iOS18, whichScripts/prepare-coverage-reports.shpicks up like any other platform's.In trial runs, the copy took 28 s, the upload about 3 minutes, the download 2 to 9.5 minutes, and installing, building, and testing about 4 minutes. So the two jobs together take about 10 to 17 minutes, and they run alongside the other jobs. The test job has the 50-minute timeout of the other simulator jobs, and the copy job stops after 15 minutes.
Run each test once and require deterministic tests. The simulator jobs ran the suite up to 100 times and stopped at the first failure.
Scripts/build.swiftno longer passes-test-iterations 100or-run-tests-until-failure, so they run it once. A newCLAUDE.mdrecords the rule that replaces the repetition: every test must be deterministic, passing every run on correct code and failing every run, or hanging until the job's timeout, on the regression it guards. Tests force interleavings with semaphores, manual executors, and test hooks, never with sleeps, wall-clock timeouts, polling, or repetition.CLAUDE.mdalso records the package's other rules: 100% code coverage, whichcodecov.ymlsets; never cancel, resume, or escalate a task while holding a lock, including the runtime's own lock on a task while it runs the task's handlers; prefer faster code over shorter code on the path that enqueues a task;guardis fine, but an early return from anifwithout anelseis not; and documentation in the plain style of The Swift Programming Language's chapter on concurrency.Run the manual executors' jobs without a dispatch queue.
ManualTaskExecutorandManualSerialExecutorin the tests wrappedrunUntilIdle()inDispatchQueue.syncon a private serial queue, which used the queue as a lock. No test callsrunUntilIdle()on one executor from two threads at once, or from a job that the executor runs, so neither a dispatch queue nor aMutexis needed. The jobs still run synchronously on the calling thread, asDispatchQueue.syncran them, and the doc comments now say to callrunUntilIdle()from one task at a time and never from one of the executor's own jobs. Test-only; the suite's wall time is unchanged within noise.Upload test results and crash reports when a test job fails. An iOS test process on #96 died without a message, and the job kept nothing that showed why. When a job fails, the two
xcodebuildjobs now upload their result bundles (.build/derivedData/*/Logs/Test/*.xcresult) and the crash reports in~/Library/Logs/DiagnosticReports/*.ips, and the "Swift Build Xcode" and Thread Sanitizer jobs upload the crash reports. Each upload is named after its job, is kept for 7 days, and uploads nothing when there are no files. A job that hits its time limit is cancelled rather than failed, so it uploads nothing, but a hang leaves no crash report anyway.Why the iOS 18 jobs work this way
Each step works around something that failed in the trial runs:
xcodebuild -downloadPlatform iOS -buildVersion 22F77fails with "iOS 22F77 is not available for download", and thexcode-27runner has no older Xcode. So the image comes from themacos-15runner.macos-15fails at random.xcodebuild -downloadPlatform iOS -buildVersion 22F77 -exportPathwith Xcode 26.1.1 wrote the disk image, then exited with code 70 after "Unable to connect to simulator." The copy job copies the disk image that is already on the runner instead.xcode-27runner's disk is too full. The runner holds about 69 GB of simulator runtimes, and adding the image failed with "Cannot copy the image because the disk is almost full". The install script deletes every runtime except the 27.2 runtime of each platform, and also the iPhone-only iOS 27.2 runtime (build 24B91016s). It then waits until no runtime is still being deleted.sudo xcodebuild -importPlatform, and withsudo xcrun simctl runtime addif Xcode still lists no iOS 18 runtime afterward. It also builds the runtime's dyld shared cache before the simulator first boots.What the iOS 18 job covers
In the trial run, the suite passed on iOS 18.5, and Swift Testing skipped the 29 tests that need iOS 26 with "Requires iOS 26". So the job runs every test that doesn't need iOS 26.
It is the first CI job that runs the queues on an OS without priority escalation. Before iOS 26,
Turnstakes its#availablefallback path: a task waits for its turn without escalating the task ahead of it, andTurn.register(_:)registers nothing. Until now, tests reached that path only throughTurns(escalatesPriority: false), and no queue's tests ran on it.This PR adds no tvOS 18, watchOS 11, or visionOS 2 jobs.
macos-15has those runtimes installed too, so the same approach should work for each, but each would be another pair of jobs moving about 9 GB, and iOS matters most.The remaining loop tests
A few older tests loop to make a bad interleaving more likely, because no deterministic test yet catches what they catch: the
sendsEventsInOrdertests, theexecutesAsyncBlocksAtomicallytests, andtask_isNotReentrantandthrowingTask_isNotReentrant. They stay as backstops. Each simulator job now runs them once instead of up to 100 times, so they are less likely to catch a rare bad interleaving on a simulator.CLAUDE.mdsays to delete such a test only once a deterministic test fails 10 of 10 runs for every bug it catches.Validation
Locally, on Linux:
ci.ymlparses as YAML, actionlint 1.7.12 reports nothing beyond the customxcode-27runner label it doesn't know, the upload paths match whatScripts/build.swiftwrites and what@actions/globmatches, both scripts passzsh -n,Scripts/build.swifttype-checks with Swift 6.4.2, andswiftformat --lintis clean. Both scripts were also run against stand-ins forxcrunandsudo, to check which runtimes they delete, when they fall back tosimctl runtime add, and that they fail when no image or runtime is found.The jobs themselves were proven in the draft spike, #98, with these differences that CI will check for the first time:
actions/upload-artifact@v7andactions/download-artifact@v8, their latest major versions. The spike used v4, which prints a Node 20 deprecation warning.Scripts/build.swiftwith a destination ofplatform=iOS Simulator,OS=18.5,name=iPad (10th generation)and code coverage on. The spike passed the new device's ID straight toxcodebuild.Series
This is stacked on #97, the top of the 2.0 series. The spike that measured these jobs was draft PR #98.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HLuVQLsTNvRnyh155N25UM