Skip to content

Fix flaky Linux SQLite CI tests#575

Merged
Aaronontheweb merged 1 commit into
akkadotnet:devfrom
Aaronontheweb:fix/flaky-sqlite-tests-574
Feb 15, 2026
Merged

Fix flaky Linux SQLite CI tests#575
Aaronontheweb merged 1 commit into
akkadotnet:devfrom
Aaronontheweb:fix/flaky-sqlite-tests-574

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Member

Summary

Fixes #574

The "Linux - SQLite" CI job has been failing consistently across PRs (#571, #572) while all other jobs pass. Three interacting bugs were identified:

Bug 1 (Primary): SqlDataOptionsEndToEndSpecBase.DisposeAsync() destroys the shared collection fixture

DisposeAsync() called _fixture.DisposeAsync(), which closes all held SQLite connections and sets _heldConnection = null. This destroys every in-memory database in the collection fixture, causing all subsequent test classes (~24 classes) to fail.

Why Linux-only: SqliteDataOptionsEndToEndSpec and MsSqliteDataOptionsEndToEndSpec have [SkipWindows] (active in Release config). On Windows CI the destructive dispose never runs. On Linux it poisons the fixture.

Fix: Removed _fixture.DisposeAsync() call — xUnit manages collection fixture lifecycle.

Bug 2: SqliteEndToEndSpec uses [CollectionDefinition] instead of [Collection]

It accidentally defines the collection instead of joining it, creating a duplicate CollectionDefinition with the real one in SqlitePersistenceSpec.cs. Compare with MsSqliteEndToEndSpec which correctly uses [Collection].

Fix: Changed to [Collection(nameof(SqlitePersistenceSpec))].

Bug 3: Container InitializeDbAsync() not defensive against null state

_heldConnection!.Add(conn) would NRE if the fixture had been prematurely disposed.

Fix: Added _heldConnection ??= new List<>() to both SqliteContainer and MsSqliteContainer.

Test plan

  • dotnet build succeeds with 0 errors
  • All 310 SQLite tests pass in Release config on Linux (306 passed, 4 skipped)
  • DataOptions end-to-end tests specifically verified passing
  • CI validates full test matrix including the previously-failing Linux SQLite job

Three interacting bugs caused the "Linux - SQLite" CI job to fail consistently:

1. SqlDataOptionsEndToEndSpecBase.DisposeAsync() called _fixture.DisposeAsync(),
   destroying the shared collection fixture's in-memory databases and poisoning
   all subsequent test classes. This only manifested on Linux because the
   DataOptions specs have [SkipWindows] (active in Release config).

2. SqliteEndToEndSpec used [CollectionDefinition] instead of [Collection],
   creating a duplicate collection definition instead of joining the existing one.

3. SqliteContainer.InitializeDbAsync() used a null-forgiving operator on
   _heldConnection, which would NRE if the fixture had been prematurely disposed.
   Made both container classes defensive with null-coalescing initialization.
@Aaronontheweb Aaronontheweb force-pushed the fix/flaky-sqlite-tests-574 branch from 131058a to e3b5521 Compare February 15, 2026 02:32
@Aaronontheweb Aaronontheweb merged commit 603a399 into akkadotnet:dev Feb 15, 2026
6 checks passed
@Aaronontheweb Aaronontheweb deleted the fix/flaky-sqlite-tests-574 branch February 15, 2026 04:55
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.

Flaky Linux SQLite CI: shared fixture destroyed by DataOptionsEndToEndSpec

1 participant