Skip to content

feat(testing): add membership provider conformance kit - #11308

Merged
ReubenBond merged 21 commits into
dotnet:mainfrom
ReubenBond:rb-membership-conformance-testkit
Sep 18, 2026
Merged

ReubenBond merged 21 commits into
dotnet:mainfrom
ReubenBond:rb-membership-conformance-testkit

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Problem

Membership provider authors need reusable behavioral checks for atomic writes, coherent canonical reads, and cleanup across independent handles and isolated cluster scopes, while keeping periodic liveness updates free of membership contention.

Solution

Add Microsoft.Orleans.Clustering.TestKit, a framework-neutral package with 27 independently invocable scenarios and actual Microsoft.Accordant-generated operation histories. The package uses Orleans Core and Accordant; its pure self-tests use independent oracles and deliberate contract-violating implementations.

Canonical mutations atomically validate TableVersion.VersionEtag, update the intended existing row, and advance the table version exactly once. Stale table snapshots, duplicate inserts, missing-row updates, and competing writes have atomic outcomes. Row ETags are opaque provider-defined metadata: a provider can independently validate a canonical row token, or ignore the supplied row ETag when table-version CAS protects the existing-row update. Positive oracles cover both stronger row checks and physical row metadata with version-only CAS.

Equal-version histories preserve every non-Dead row, retained canonical field, and table version/ETag while allowing Dead-only pruning. A newer view can establish a missing previously-live identity's terminal death. Cleanup accepts an unchanged version or valid atomic +1 batches. Allowed cleanup outcomes are bounded and their canonical row effects validated before entering the model. Row metadata can vary across reads and cleanup without defining a new canonical view.

Each owning silo publishes its own IAmAliveTime through one blind liveness-column write. Heartbeats preserve canonical membership fields and the table version/ETag; physical row ETags may change. Direct and generated cases capture row/table inputs, perform an owner heartbeat, and commit a status or vote update using those original inputs with exactly one +1 commit. Provider-native instrumentation verifies zero prerequisite reads, zero compare-and-swap operations, and exactly one periodic liveness write.

Raw IAmAliveTime reads can lag or regress, and full-row membership writes can overwrite a heartbeat with an earlier value. Canonical comparisons exclude raw liveness and row metadata. The model keeps generated owner timestamps independently from provider observations; private oracle variants exercise lag, full-row overwrite, and cheap preservation without learning observed canonical state. Runtime snapshot observed-maximum behavior remains covered by #11296.

Fixtures own independent handles, isolated scopes, explicit initialization, and bounded teardown waits. A mandatory read-only native deletion probe checks the original populated backing scope, then verifies actual deletion or invalidation before owner disposal. Generated deletion ends its history. Admitted factory, native initialization, terminal deletion/probe, and cleanup operations retain their owners through actual completion, independently of canceled caller waits. A shared cleanup task preserves late failures; teardown failure stops further generated cases and replay. Concurrent initialization shares the same three handles, and ownership registration is atomic with terminal disposal.

The self-test assembly participates in Suite=BVT / Provider=None. Pagination-sized concurrency setup preserves N actual inserts and per-commit +1 checks while using N+1 point reads plus two final full views against independently constructed canonical rows. Include the generated API surface, package metadata, and focused usage documentation.

Scope and rationale

This is an independent PR against main, carved from the recorded membership-conformance snapshot and aligned with #11296. It contains no commits from #11307. Production providers, runtime/host integrations, and stronger conformance activation in existing provider suites remain separate work. Receipt-based ReadRow retirement is a separate follow-up.

The first commit, bede893d290a9035f196f4c3ed58213d102efc6c, corrects only the legacy shared cleanup test's baseline data and assertions: old Active/Dead plus fresh Active, retaining exactly three Active rows and removing Dead rows. The separate reusable commit 4f316eaf52681b3a313571ad093cf398b9118690 checks the complete table version after rejected updates instead of requiring row-metadata equality. Both preserve the base class API and can be reused independently of the kit.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 17, 2026 22:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Provider-generated cancellations are currently misreported as test-kit timeouts instead of propagating their original failures.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds a framework-neutral membership provider conformance kit with direct scenarios, Accordant-generated histories, fixtures, test doubles, API metadata, and documentation.

Changes:

  • Added membership table runners, snapshots, models, fixtures, and diagnostics.
  • Added comprehensive idealized and faulty-provider self-tests.
  • Updated legacy cleanup coverage, packaging, solution, and provider documentation.
File Description
test/​Orleans.Runtime.Internal.Tests/​MembershipTests/​MembershipTableTestsBase.cs Updates cleanup test data and assertions.
test/​Orleans.Clustering.TestKit.Tests/​Orleans.Clustering.TestKit.Tests.csproj Adds the conformance test project.
test/​Orleans.Clustering.TestKit.Tests/​MembershipTableTestFixtureTests.cs Tests fixture ownership and lifecycle.
test/​Orleans.Clustering.TestKit.Tests/​MembershipTableTestDataTests.cs Tests deterministic membership data.
test/​Orleans.Clustering.TestKit.Tests/​MembershipTableSnapshotTests.cs Tests snapshot and history behavior.
test/​Orleans.Clustering.TestKit.Tests/​MembershipTableModelTests.cs Tests model transitions.
test/​Orleans.Clustering.TestKit.Tests/​MembershipTableModelBasedTestRunnerTests.cs Tests generated-runner behavior.
test/​Orleans.Clustering.TestKit.Tests/​MembershipTableConformanceTests.cs Runs direct and generated conformance scenarios.
test/​Orleans.Clustering.TestKit.Tests/​IdealizedMembershipTableTests.cs Tests the idealized backend.
test/​Orleans.Clustering.TestKit.Tests/​IdealizedMembershipTable.cs Provides the independent idealized backend.
test/​Orleans.Clustering.TestKit.Tests/​FaultyMembershipTableTests.cs Verifies deliberate contract violations.
test/​Orleans.Clustering.TestKit.Tests/​FaultyMembershipTable.cs Provides faulty-provider mutations.
test/​Orleans.Clustering.TestKit.Tests/​ClusteringTestKitDiagnosticsTests.cs Tests diagnostic formatting.
test/​Orleans.Clustering.TestKit.Tests/​AssemblyInfo.cs Assigns BVT clustering test traits.
src/​Orleans.Clustering.TestKit/​README.md Documents package usage and guarantees.
src/​Orleans.Clustering.TestKit/​Orleans.Clustering.TestKit.csproj Defines the new package.
src/​Orleans.Clustering.TestKit/​MembershipTableTestRunner.cs Implements direct conformance scenarios.
src/​Orleans.Clustering.TestKit/​MembershipTableTestFixture.cs Manages handles, scopes, and teardown.
src/​Orleans.Clustering.TestKit/​MembershipTableTestData.cs Supplies deterministic test data.
src/​Orleans.Clustering.TestKit/​MembershipTableModelBasedTestRunner.cs Runs generated Accordant histories.
src/​Orleans.Clustering.TestKit/​MembershipTableModel.cs Defines the behavioral model.
src/​Orleans.Clustering.TestKit/​ClusteringTestKitDiagnostics.cs Defines conformance failures and diagnostics.
src/​Orleans.Clustering.TestKit/​ClusteringMembershipSnapshot.cs Implements immutable observations and history validation.
src/​api/​Orleans.Clustering.TestKit/​Orleans.Clustering.TestKit.cs Adds generated public API metadata.
Orleans.slnx Adds source and test projects to the solution.
docs/​site/​src/​data/​unpublished-api-packages.json Marks the package as unpublished.
docs/​site/​src/​data/​external-link-allowlist.json Allows the pre-publication NuGet link.
docs/​site/​src/​content/​docs/​resources/​nuget-packages.md Lists the package.
docs/​site/​src/​content/​docs/​implementation/​provider-authoring.md Documents membership conformance usage.
Directory.Packages.props Pins package dependencies for the kit.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 18, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

It introduces a large public testing framework with generated histories and provider-lifetime semantics requiring final human validation.

Review effort: Lite
Findings: 1 Medium severity

Open (1)

Copilot AI review requested due to automatic review settings September 18, 2026 09:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Concurrent fixture disposal can race with handle registration and leave a factory-created handle undisposed.

Review effort: Lite
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Synchronize handle registration with fixture disposal

src/​Orleans.Clustering.TestKit/​MembershipTableTestFixture.cs:128

The post-factory _disposed check is not atomic with adding the handle to _handles and _clusters. DisposeAsync can set _disposed and finish iterating those collections after this check but before lines 130-132, leaving a successfully created handle unregistered and never disposed. Protect the check-and-register sequence with the same lifecycle synchronization used by disposal.

@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 82.47% (114,180 / 138,450)
Branches 71.81% (33,036 / 46,004)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested 986e5c7, not current main dcf2925.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

Copilot AI review requested due to automatic review settings September 18, 2026 15:12
@ReubenBond

Copy link
Copy Markdown
Member Author

Addressed the body-only finding Synchronize handle registration with fixture disposal in review 5246252042 with commit 5beec78.

Handle acceptance and registration now use the same lifecycle lock as marking the fixture disposed and snapshotting its owned handles/live scopes. Provider factories and disposal callbacks run outside the lock. A factory completing after disposal or terminal history retirement disposes its returned owner before reporting the lifetime error; cleanup failures still propagate. Teardown iterates stable ownership snapshots.

Added gated regressions for factory completion during/after disposal, registration before disposal, terminal retirement during a pending factory, and late-owner disposal failure. They assert exact disposal counts and zero calls through invalidated providers without sleeps. Fixture and native-deletion regression classes pass on Release net8.0 and net10.0 (24 tests per target, zero failures/skips); both projects pass whitespace verification.

Audited the other review bodies and inline threads: the only other actionable finding was provider cancellation being mislabeled as a runner timeout, already fixed in 247e2d9 with its inline thread resolved. The PR remains draft for human review; CI is running on the new head.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Concurrent InitializeAsync calls can create extra and potentially uninitialized handles.

Review effort: Lite
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Medium severity Serialize concurrent fixture initialization

src/​Orleans.Clustering.TestKit/​MembershipTableTestFixture.cs:104

Two callers can both observe _initialized == false and run the three factory calls concurrently. They then overwrite First/Second/OtherCluster; depending on timing, some of the six acquired handles are never initialized, while the fixture reports successful initialization and retains extra owners. Serialize initialization (for example, cache and await one shared initialization task) so concurrent callers share the same three handles.

Copilot AI review requested due to automatic review settings September 18, 2026 18:36
@ReubenBond

Copy link
Copy Markdown
Member Author

Addressed the foreign-read mutant owner finding from review 5251235057 in 16918a7. The temporary cross-cluster provider is now owned by an await using test handle and disposed after the read, including failure paths. The read runs outside the backend lock instead of blocking on an async result inside it.

The deliberate cross-cluster violation is still detected, and its test now asserts exactly four created owners and four disposed owners. All 30 direct-guarantee mutant cases pass on both Release net8.0 and net10.0, with zero skips; formatting verification passes.

The previously resolved accepted-handle lifetime fix remains in place for live, retired, and disposed branches. Distinct wrappers retain explicit per-handle ownership semantics; the fixture rejects duplicate provider instances rather than inferring ownership of opaque resources.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

A late factory wrapper around an already-owned table can dispose the accepted owner before pending operations complete.

Review effort: Lite
Findings: None

@ReubenBond

ReubenBond commented Sep 18, 2026 •

Copy link
Copy Markdown
Member Author

Regarding the overview in review 5251343786: the exact already-accepted handle case is guarded before live/retired/disposed rejection and covered by the gated CreateAdditionalHandle_LateAcceptedHandleWaitsForOtherAdmittedOperations cases.

A distinct MembershipTableTestHandle has an explicitly supplied resource owner/disposer. The fixture cannot infer whether two arbitrary delegates share a resource merely because their tables are reference-equal. A factory sharing a native owner must correctly lease or reference-count that owner across its handles. This follows the constructor contract: the supplied disposer owns the resources for that handle. Duplicate provider instances are rejected as fixture errors. Newly acquired rejected wrappers still have their own declared resources cleaned up, while accepted handles remain under the fixture's shared teardown task.

Concrete evidence in MembershipTableTestFixtureTests:

  • CreateAdditionalHandle_LateAcceptedHandleWaitsForOtherAdmittedOperations covers both history retirement and concurrent disposal, retaining the accepted owner while native verification is paused.
  • CreateAdditionalHandle_DuplicateTableDisposesOnlyRejectedWrapperBeforeTeardown proves a distinct rejected wrapper is disposed exactly once, while the accepted owner remains untouched; returning the exact accepted handle again also preserves it.
  • CreateAdditionalHandle_RejectedWrapperCleanupFailurePreservesDuplicateFailure proves rejected-owner cleanup errors retain the original conformance failure and remain observable through shared teardown.
  • Initialize_SingletonFactory_IsRejectedAndAcquiredOwnerDisposedOnce covers repeated identical handles during initialization.

The no-change disposition concerns only speculative sharing behind distinct opaque disposer delegates. No additional ownership protocol, API change, or linear-setup change is warranted. Receipt-based ReadRow retirement remains a separate follow-up.

@ReubenBond
ReubenBond marked this pull request as ready for review September 18, 2026 19:06
Copilot AI review requested due to automatic review settings September 18, 2026 19:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The shared atomic-write regression is weakened and teardown can block before its timeout is reached.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Do not run synchronous teardown inline before the timeout

src/​Orleans.Clustering.TestKit/​MembershipTableTestFixture.cs:418

CompleteDisposalAsync is invoked synchronously here, and its first delete/disposer call is executed inline until it returns an incomplete task. A legacy IMembershipTable implementation can legally perform blocking work before returning its tokenless Task, so DisposeAsync may block indefinitely before it reaches completion.WaitAsync(waitTimeout), defeating the documented 30-second caller bound. Start the completion operation asynchronously (or otherwise isolate synchronous provider dispatch) before waiting.

Copilot AI review requested due to automatic review settings September 18, 2026 19:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Teardown does not coordinate all direct membership operations, and synchronous cleanup dispatch can bypass the documented timeout.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Teardown does not wait for ordinary membership operations

src/​Orleans.Clustering.TestKit/​MembershipTableTestFixture.cs:413

The pending-operation set only contains fixture-internal factory, initialization, deletion, and probe tasks, but the runner invokes ReadAllAsync/ReadRowAsync/InsertRowAsync/UpdateRowAsync/UpdateIAmAliveAsync/CleanupDefunctSiloEntriesAsync directly with a cancellable token. For a tokenless provider, IMembershipTable's default async adapters cancel the caller's wait while the underlying operation continues; a scenario timeout or cancellation can therefore reach this disposal snapshot with provider work still using the owner, after which lines 443-453 delete and dispose it. Track all provider invocations with the fixture's lifetime coordination (including direct foreign-deletion calls), or defer owner disposal until those operations complete.

This issue also appears on line 418 of the same file.

Copilot AI review requested due to automatic review settings September 18, 2026 20:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The conformance kit, lifecycle and concurrency handling, self-tests, packaging, generated API, and documentation were reviewed with no unresolved correctness issues.

Review effort: Lite
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 18, 2026 20:19
@ReubenBond

Copy link
Copy Markdown
Member Author

Disposition for the lifecycle overview/body in review 5252116478:

  • Synchronous cleanup dispatch: confirmed and fixed in f28da90. With no incomplete admitted tasks, inline dispatch could execute a synchronously blocking delete/disposer before the bounded caller wait began. Cleanup now starts on a worker task while the same shared completion task retains ownership and late failures. The gated synchronous-delete and synchronous-disposer regressions failed before the fix and pass afterward; fixture/deletion/cleanup classes pass 43 tests per framework on Release net8.0 and net10.0, zero skips.
  • Ordinary membership calls: the approved scope remains fixture-owned factory, initialization, terminal deletion/probe, and cleanup work. Ordinary calls retain their scenario cancellation token and the provider's actual cancellation behavior. Tracking a returned canceled compatibility-adapter task cannot expose its hidden native task, while universally passing None would change the behavior under test. The kit does not promise quiescence of all hidden ordinary work after cancellation. Handle owners release declared resources according to the actual SDK close, abort, or drain contract, with errors visible; some SDKs legitimately fault in-flight I/O. No blanket draining guarantee, provider wrapper, or all-call ownership layer is being introduced. A concrete supported owner violating its real SDK resource contract should be investigated at that boundary.

The README now states these boundaries explicitly. Public APIs, blind heartbeat behavior, table-version CAS semantics, and linear pagination setup are unchanged.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Late duplicate handles wrapping an already-owned provider table can be disposed before shared teardown completes.

Review effort: Lite
Findings: None

@ReubenBond

Copy link
Copy Markdown
Member Author

Current-head review 5252300970 reports no findings and repeats the distinct-wrapper ownership overview. The disposition remains the documented one in the ownership response: exact already-accepted handle identities are retained through pending work, with both disposed/retired gated regressions; each distinct rejected handle owns its declared resources, and factories must correctly lease/reference-count any shared opaque native owner. Table reference equality cannot establish arbitrary delegate ownership. No additional ownership protocol or all-ordinary-call tracking layer is introduced.

The current table-CAS contract and native single-attempt guidance are independent of that ownership boundary. Row ETags can vary as metadata; canonical state and the table version/ETag remain protected, and original pre-heartbeat row/table inputs must still permit one canonical update.

@ReubenBond
ReubenBond merged commit f50fdee into dotnet:main Sep 18, 2026
73 checks passed
@ReubenBond
ReubenBond deleted the rb-membership-conformance-testkit branch September 18, 2026 22:03
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants