Skip to content

Stop conjoined_multi_tenancy and its partitioning twin sharing a schema - #5087

Merged
jeremydmiller merged 1 commit into
masterfrom
fix/mixed-multi-tenants-schema-clash
Jul 30, 2026
Merged

Stop conjoined_multi_tenancy and its partitioning twin sharing a schema#5087
jeremydmiller merged 1 commit into
masterfrom
fix/mixed-multi-tenants-schema-clash

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Fixes the CI failure that blocked #5085 from merging. Not caused by that PR — it is a latent isolation bug of the same family as #5070, exposed by xunit v3's parallelism rather than created by it.

The failure

await session.Query<User>().CountAsync()  should be 2 but was 4

hitting can_query_on_multi_tenanted_and_non_tenanted_documents in both conjoined_multi_tenancy and conjoined_multi_tenancy_with_partitioning, in the same run. Two independent flakes don't synchronise like that; a contended shared resource does.

Cause

Both classes build their own DocumentStore on the same hard-coded schema:

opts.DatabaseSchemaName = "mixed_multi_tenants";

then DeleteAllDocumentsAsync(), bulk-insert two User rows, and assert the count is 2. Neither class carried a [Collection] attribute, so xunit v3 puts them in separate collections and runs them in parallel — both insert before either counts, and both see 4.

Fix, from both directions

  • The two classes now share the mixed_multi_tenancy collection, so xunit will not run them concurrently.
  • conjoined_multi_tenancy gets its own schema, mixed_multi_tenants_conjoined, so they no longer touch the same tables at all.

The docs wrinkle

The schema name sits inside #region sample_tenancy-mixed-tenancy-non-tenancy-sample in both files — and mdsnippets renders both into docs/documents/multi-tenancy.md, the second as a duplicate -sample-1 anchor. (That duplication is a pre-existing wart worth cleaning up separately: the same sample is published twice.)

So the rename was applied to the copy that only feeds the duplicate anchor. The primary sample readers actually see is byte-identical; the regenerated duplicate block is committed. The [Collection] attributes sit outside the region markers, so they don't appear in the docs at all.

Verification

  • DocumentDbTests: 1089/1090, 0 failures on both net9.0 and net10.0.
  • mdsnippets gate clean — the only doc content change is the one schema line inside the duplicate block, confirmed by line position to be after the -sample-1 anchor and not in the primary. markdownlint and cspell clean.

Being straight about what the green run does and doesn't prove: the suite also passed on clean master, so a passing local run does not by itself demonstrate the fix — the collision needed CI's parallel timing to surface. The justification is the mechanism (shared literal schema + separate collections + wipe-then-count), and CI is where it gets exercised for real.

🤖 Generated with Claude Code

Both classes build their own DocumentStore on the hard-coded schema
"mixed_multi_tenants", wipe it with DeleteAllDocumentsAsync and then assert on
global counts. Neither carried a [Collection] attribute, so xunit v3 puts them in
separate collections and runs them in parallel: both insert their two User rows
before either counts, and both see 4. That is the CI failure

    await session.Query<User>().CountAsync() should be 2 but was 4

hitting can_query_on_multi_tenanted_and_non_tenanted_documents in BOTH classes in
the same run -- two independent flakes do not synchronise like that; a contended
shared resource does.

Fixed from both directions:

- the two classes now share the "mixed_multi_tenancy" collection, so xunit will
  not run them concurrently
- conjoined_multi_tenancy gets its own schema, mixed_multi_tenants_conjoined, so
  they no longer touch the same tables at all

The schema name sits inside #region sample_tenancy-mixed-tenancy-non-tenancy-sample
in both files, and mdsnippets renders BOTH into docs/documents/multi-tenancy.md --
the second as the duplicate `-sample-1` anchor. The rename was applied to the copy
that only feeds that duplicate, so the primary sample readers see is unchanged;
the regenerated duplicate block is committed.

Note this is a latent isolation bug of the same family as #5070, exposed by v3's
parallelism rather than caused by it.

Verified: DocumentDbTests net10.0 is 1089/1090 with 0 failures. Worth being
straight about the limits of that -- the suite also passed on clean master, so a
green local run does not by itself prove the fix. The justification is the
mechanism (shared literal schema + separate collections + wipe-then-count), and
CI is where it gets exercised for real. mdsnippets gate, markdownlint and cspell
all clean.
@jeremydmiller
jeremydmiller merged commit b33846d into master Jul 30, 2026
10 checks passed
@jeremydmiller
jeremydmiller deleted the fix/mixed-multi-tenants-schema-clash branch July 30, 2026 00:05
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.

1 participant