Skip to content

test(postgresql): move DatabaseWithTablesTests off the shared public schema (weasel#407) - #410

Merged
jeremydmiller merged 1 commit into
masterfrom
fix/407-dwt-tests-share-public-schema
Jul 30, 2026
Merged

test(postgresql): move DatabaseWithTablesTests off the shared public schema (weasel#407)#410
jeremydmiller merged 1 commit into
masterfrom
fix/407-dwt-tests-share-public-schema

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Closes #407.

Symptom

DatabaseWithTablesTests.detect_and_apply_schema_changes failed intermittently in full-suite runs, ~1 in 3–6 locally, with either:

Npgsql.PostgresException : XX000: could not open relation with OID 659774
  at Weasel.Postgresql.Tables.Table.readIndexesAsync(...) Table.FetchExisting.cs:365
Npgsql.PostgresException : 42P01: relation "public.dwt_contacts" does not exist

Reproduced on clean master. It never failed with the class run in isolation (8 filtered runs), so it was cross-collection interference, not a bug in the test's own logic.

Cause

The class is [Collection("integration")] and ResetSchema() resets its SchemaName"integration" — but the tables were created in public:

var table = db.AddTable(new PostgresqlObjectName("public", "dwt_contacts"));

Nothing here isolates public, and at least nine other test files also write to it: PostgresqlMigratorTests, create_and_teardown_schemas, Tables/TableTests, Tables/IndexDefinitionTests, Tables/creating_tables_in_database, Tables/ForeignKeyTests, Tables/Indexes/FullTextIndexDefinitionTests, Functions/FunctionBodyTests, Views/ViewTests.

xUnit serialises a collection against itself but runs different collections in parallel, so another collection could drop objects in public mid-test:

  • directly between apply and assert → 42P01
  • between the pg_index catalog row being read and the relation being opened → XX000: could not open relation with OID, the classic Postgres catalog race

Change

Create the tables in integration, so ResetSchema() actually covers them. Same for the siblings dwt_users and dwt_people, which had identical exposure. A class-level comment records why, so they don't drift back.

Test-only — no product code touched.

Verification

12 consecutive full-suite runs on the exact configuration that used to fail (net10.0, case-sensitive), zero failures — against a prior rate of roughly 1 in 3–6.

Note

The broader hazard remains: tests sharing public across parallel collections is a standing source of this failure mode. Worth deciding separately whether public should be off-limits to anything that creates or drops objects.

🤖 Generated with Claude Code

…schema (weasel#407)

detect_and_apply_schema_changes failed intermittently in full-suite runs,
roughly 1 in 3-6 locally, with either

    XX000: could not open relation with OID 659774
      at Table.readIndexesAsync ... Table.FetchExisting.cs:365

or

    42P01: relation "public.dwt_contacts" does not exist

It never failed with the class run in isolation, so it was cross-collection
interference rather than anything wrong with the test itself.

The class is [Collection("integration")] and ResetSchema() resets
"integration", but the tables were created in "public", which nothing here
isolates and which at least nine other test files also write to. xUnit
serialises a collection against itself but runs different collections in
parallel, so another collection could drop objects in "public" mid-test:
directly, giving 42P01, or between the pg_index catalog row being read and
the relation being opened, giving the OID error.

Create the tables in "integration" instead, so ResetSchema() actually
covers them. Same change for the sibling dwt_users and dwt_people, which had
the same exposure.

Verified: 12 consecutive full-suite runs on the configuration that used to
fail (net10.0, case-sensitive), zero failures.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jeremydmiller
jeremydmiller merged commit 924b846 into master Jul 30, 2026
16 checks passed
@jeremydmiller
jeremydmiller deleted the fix/407-dwt-tests-share-public-schema branch July 30, 2026 16:09
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: DatabaseWithTablesTests.detect_and_apply_schema_changes races other collections over the shared 'public' schema

1 participant