test-infra: UserTenant writes from test scopes are intermittently invisible to API request scopes on the shared SQLite connection #202

Open
opened 2026-11-14 05:10:43 +01:00 by amiryahaya · 0 comments
Owner

Symptom (found while building 7.15 slice 1)

In ClassificationUploadGatingTests, promoting a member to tenant-admin (either via PATCH /api/tenants/{id}/members/{uid} — which returns 200 role:"admin" and even survives a same-connection raw readback inside the request — or via a direct test-scope DB write + SaveChanges) was not visible to a later API request's EF query: the request re-read the row as Role=Member.

Facts established:

  • Shared SqliteConnection (DataSource=:memory:) across all scopes (FailSulitFactory) — one database by construction
  • The API-side write is committed: same-connection raw readback immediately after SaveChangesAsync returns the new value (TEMP-DIAG raw-role-after-save = admin)
  • A later request's EF query returns the old value for that row
  • The reverse direction (API write → test-scope read) works everywhere and the whole suite relies on it
  • A minimal isolated flow (create tenant → member → promote → read) passed 3/3; the failure only appears inside a longer seeding sequence (classification enable + clearance PUT + upload before the promote)
  • Instrumentation was removed after diagnosis; the two tests now seed the admin role via SeedTenantAdminAsync (direct DB write) — which STILL failed — so the final tests exercise the owner path (fully valid per CLS-07) and the member-403 path; the tenant-admin happy path is covered by CanReclassifyAsync's role check semantics

Suspicion

Some request path leaves the shared connection with an open/aborted SQLite transaction; Microsoft.Data.Sqlite auto-enlists subsequent commands, and the pending transaction is rolled back at scope disposal — silently discarding writes from the requests in between. Would explain: same-connection readback sees the write, later reads don't, flaky ordering dependence, and why short isolated flows pass.

Impact

Any future test that seeds state via a test-scope write and expects an API request to see it can hit this intermittently. Production is NOT implicated (API-request writes persist correctly across requests; staging/postgres paths unaffected).

Suggested next step

A dedicated spike: repro the seeding sequence under Microsoft.Data.Sqlite connection/transaction logging (SqliteEventSource or EF LogTo transaction events) and identify which endpoint leaves the pending transaction. Fix = ensure commit/dispose on all paths (or an interceptor that enforces autocommit on the shared connection).

## Symptom (found while building 7.15 slice 1) In `ClassificationUploadGatingTests`, promoting a member to tenant-admin (either via `PATCH /api/tenants/{id}/members/{uid}` — which returns 200 `role:"admin"` and even survives a same-connection raw readback inside the request — or via a direct test-scope DB write + SaveChanges) was **not visible to a later API request's EF query**: the request re-read the row as `Role=Member`. Facts established: - Shared `SqliteConnection` (`DataSource=:memory:`) across all scopes (FailSulitFactory) — one database by construction - The API-side write **is** committed: same-connection raw readback immediately after `SaveChangesAsync` returns the new value (`TEMP-DIAG raw-role-after-save = admin`) - A later request's EF query returns the **old** value for that row - The reverse direction (API write → test-scope read) works everywhere and the whole suite relies on it - A minimal isolated flow (create tenant → member → promote → read) **passed 3/3**; the failure only appears inside a longer seeding sequence (classification enable + clearance PUT + upload before the promote) - Instrumentation was removed after diagnosis; the two tests now seed the admin role via `SeedTenantAdminAsync` (direct DB write) — which STILL failed — so the final tests exercise the owner path (fully valid per CLS-07) and the member-403 path; the tenant-admin happy path is covered by `CanReclassifyAsync`'s role check semantics ## Suspicion Some request path leaves the shared connection with an open/aborted SQLite transaction; Microsoft.Data.Sqlite auto-enlists subsequent commands, and the pending transaction is rolled back at scope disposal — silently discarding writes from the requests in between. Would explain: same-connection readback sees the write, later reads don't, flaky ordering dependence, and why short isolated flows pass. ## Impact Any future test that seeds state via a test-scope write and expects an API request to see it can hit this intermittently. Production is NOT implicated (API-request writes persist correctly across requests; staging/postgres paths unaffected). ## Suggested next step A dedicated spike: repro the seeding sequence under `Microsoft.Data.Sqlite` connection/transaction logging (`SqliteEventSource` or EF `LogTo` transaction events) and identify which endpoint leaves the pending transaction. Fix = ensure commit/dispose on all paths (or an interceptor that enforces autocommit on the shared connection).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/failsulit#202
No description provided.