Skip to content

Run WMFData tests serially to fix global-environment race#5965

Open
davmonk wants to merge 1 commit into
wikimedia:mainfrom
davmonk:serialize-wmfdata-tests
Open

Run WMFData tests serially to fix global-environment race#5965
davmonk wants to merge 1 commit into
wikimedia:mainfrom
davmonk:serialize-wmfdata-tests

Conversation

@davmonk

@davmonk davmonk commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

Several WMFDataTests suites mutate the shared WMFDataEnvironment.current singleton (mediaWikiService / basicService / stores) in their setUp/init. Swift Testing runs suites in parallel by default, so concurrently-running suites can overwrite each other's mocked services mid-test. This produces intermittent failures — e.g. WMFWatchlistDataControllerTests.fetchWatchlistWithProjectFilter failing with .serviceError(unableToPullData) when another suite swapped the global service out from under it.

Why the obvious fixes don't work

  • @Suite(.serialized) per suite (already present on several suites) only serializes tests within one suite — separate suites still run in parallel relative to one another. This is a cross-suite race.
  • setUp/tearDown snapshot-restore can't help either: concurrent suites stomp the shared global regardless of restore.
  • The target also mixes Swift Testing structs and XCTest classes, so a single nested .serialized base suite would require converting the XCTest classes — large, risky churn.

Fix

Disable parallel execution for the whole WMFDataTests target in its test plan ("parallelizable": false). This is the documented, framework-correct way to serialize an entire target (confirmed by Swift Testing maintainers that the test-plan parallelization setting gates Swift Testing, not just XCTest).

Verification

  • Instrumented the run output: max concurrent Swift Testing tests drops from 7 → 1 (fully serial).
  • Full WMFData suite passes green across repeated runs.
  • The suite is small, so the serial-execution time cost is negligible.

🤖 Generated with Claude Code

Multiple WMFDataTests suites mutate the shared WMFDataEnvironment.current
singleton (mediaWikiService/basicService/stores) in their setUp/init.
Swift Testing runs suites in parallel by default, so concurrently running
suites could overwrite each other's mocked services mid-test, producing
intermittent failures (e.g. WMFWatchlistDataControllerTests failing with
.serviceError(unableToPullData) when another suite swapped the global
service).

Per-suite @suite(.serialized) does not fix this: it only serializes tests
within a single suite, not separate suites relative to one another. The
race is across suites (and the target mixes Swift Testing structs with
XCTest classes), so the reliable, low-churn fix is to disable parallel
execution for the whole WMFDataTests target in its test plan. Verified
locally: max concurrent Swift Testing tests drops from 7 to 1, and the
suite passes green across repeated runs. The suite is small, so the
serial-execution time cost is negligible.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@davmonk
davmonk force-pushed the serialize-wmfdata-tests branch from 4bc63e8 to 59cb05b Compare July 14, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant