Skip to content

[CHORE] Fix race condition in SwiftTestingTraitTests mock SessionManager#249

Merged
ypopovych merged 1 commit into
mainfrom
chore/fix-swift-testing-trait-race
May 14, 2026
Merged

[CHORE] Fix race condition in SwiftTestingTraitTests mock SessionManager#249
ypopovych merged 1 commit into
mainfrom
chore/fix-swift-testing-trait-race

Conversation

@ypopovych

@ypopovych ypopovych commented May 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes intermittent Expectation failed: session.modules[test.ddModule]?.suites[test.ddSuite] → nil in SwiftTestingTraitTests.
  • The trait's provideScope verification blocks run concurrently across the file's top-level scopes (2 suites + 3 free @Test funcs). When the scope ending the module called stop(), Mocks.SessionManager nilled _session. A slower verifier awaiting suiteProvider.session.session after that point would re-enter sessionAndConfig and bootstrap a brand-new empty session via provider.startSession, so the subsequent session.modules[...]?.suites[...] lookup returned nil.
  • Keep _session set after stop() and gate the observer notifications with a _stopped flag so willFinish/didFinish/end still fire exactly once. Concurrent readers post-stop now observe the same (now-ended) session instead of a fresh one.

Test plan

  • xcodebuild test-without-building for SwiftTestingTraitTests, SwiftTestingTaggedSuiteTests, testFuncRetryErrorShouldFail, testFuncRegistration, zzzzFuncCancel — 10 consecutive runs all pass, no session.modules → nil failures.
  • CI green.

🤖 Generated with Claude Code

…Tests

The trait test's verification blocks run concurrently across top-level
scopes. When the last-finishing scope called stop(), _session was nilled,
so a slower verifier awaiting through sessionAndConfig would bootstrap a
fresh empty session — making session.modules[test.ddModule]?.suites[...]
nil. Keep the session reference after stop() and gate observer
notifications with a _stopped flag so the side effects only fire once.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@ypopovych
ypopovych requested review from a team as code owners May 14, 2026 10:26
@ypopovych ypopovych changed the title chore: fix race condition in SwiftTestingTraitTests mock SessionManager [CHORE] fix race condition in SwiftTestingTraitTests mock SessionManager May 14, 2026
@ypopovych ypopovych changed the title [CHORE] fix race condition in SwiftTestingTraitTests mock SessionManager [CHORE] Fix race condition in SwiftTestingTraitTests mock SessionManager May 14, 2026
@ypopovych
ypopovych requested a review from juan-fernandez May 14, 2026 10:38
@ypopovych
ypopovych merged commit cca3322 into main May 14, 2026
17 checks passed
@ypopovych
ypopovych deleted the chore/fix-swift-testing-trait-race branch May 14, 2026 11:15
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