Skip to content

test: a seeded SQLite database answers one query at a time - #150

Merged
CaffeinatedCoder merged 1 commit into
release/2.3.0from
test/ef-variant-sqlite-lock
Oct 29, 2026
Merged

CaffeinatedCoder merged 1 commit into
release/2.3.0from
test/ef-variant-sqlite-lock

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #148

Problem

QueryTranslationVariantTests caches one open in-memory SqliteConnection per model, which is seeded once and then only read. Since #142, SqlServerQueryVariantTests reads that same cache through QueryTranslationVariantTests.Run from its own collection (SQL Server), in parallel with the SQLite class. A SqliteConnection isn't thread-safe, so two commands at once on one connection fail with SQLite Error 5: 'database is locked'.

This only fails on the Linux leg, the only one that runs the Needs=Docker classes. It failed twice on #141's run 40889709782, with a different case each time. Windows passed both times.

Change

  • QueryTranslationVariantTests.Run holds the cached connection's lock while it builds and runs a case's query. Within the SQLite class the cases already ran one after another, so the lock only orders this class's reads against the SQL Server class's.
  • Databases' summary says why.

Tests

  • New A_seeded_database_read_by_many_cases_at_once_answers_each_alike: 400 reads of one seeded database in parallel, each holding the same rows.
    • Seeded with the lock made a no-op (lock (new object())): fails with database is locked. Restored: passes.
  • QueryTranslationVariantTests locally: 9,610 passed, 462 skipped, in 52 s.
  • The SQL Server leg runs in CI's Linux job.

🤖 Generated with Claude Code

QueryTranslationVariantTests caches one open in-memory SqliteConnection per
model. Since #142, SqlServerQueryVariantTests reads the same cache from its own
collection, in parallel with this class. A connection is not thread-safe, so two
commands at once failed with "database is locked" on the Linux leg, the only
leg that runs the Docker classes: twice on #141's run 40889709782. Each read
now holds the connection's lock.

A_seeded_database_read_by_many_cases_at_once_answers_each_alike runs 400
reads of one database in parallel. With the lock taken out it fails with
"database is locked"; with it, it passes, and the class's 9,610 cases pass in
52 s.

Closes #148

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CaffeinatedCoder CaffeinatedCoder added this to the 2.3.0 milestone Oct 29, 2026
@CaffeinatedCoder CaffeinatedCoder added tests Adds or changes tests only (tests, probes, harnesses); no library code package/efcore Affects CodoMetis.TypeKit.EntityFrameworkCore labels Oct 29, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 99c6032 into release/2.3.0 Oct 29, 2026
8 of 9 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the test/ef-variant-sqlite-lock branch October 29, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package/efcore Affects CodoMetis.TypeKit.EntityFrameworkCore tests Adds or changes tests only (tests, probes, harnesses); no library code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant