Skip to content

test: wait for grain call before checking cancellation - #10319

Merged
ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:reubenbond-fix-cancellation-liveness-race
Aug 1, 2026
Merged

ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:reubenbond-fix-cancellation-liveness-race

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

The delayed grain cancellation test assumed that a positive timer meant the grain method had started. On slower activation paths, cancellation can remove the request from the activation's waiting queue and return OperationCanceledException without invoking the method, leaving the test waiting for a cancellation record which can never be written.

Add a test observer handshake emitted from inside the grain method and wait for it before scheduling delayed cancellation. This preserves immediate-cancellation coverage while making the delayed cases deterministically exercise cancellation of a running call. No runtime product behavior is changed.

Microsoft Reviewers: Open in CodeFlow

Ensure delayed cancellation cases observe that the grain method has started before expecting its catch block to record cancellation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 44628696-d4d6-43f1-802d-dcf7a0d8952a
Copilot AI review requested due to automatic review settings August 1, 2026 06:31

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.

Pull request overview

This PR makes the delayed cancellation path in CancellationTokenTests deterministic by adding an explicit “call started” handshake emitted from inside the grain method, avoiding cases where cancellation can occur before the grain method runs on slower activation paths.

Changes:

  • Update the cancellation test to wait for an in-method start notification before scheduling delayed cancellation.
  • Introduce a test-only grain observer interface and an observer implementation to signal when the grain method begins executing.
  • Add a new grain method wrapper which notifies the observer before delegating to the existing long-wait implementation.
Show a summary per file
File Description
test/Orleans.Runtime.Tests/CancellationTests/CancellationTokenTests.cs Waits for an explicit “call started” signal before scheduling delayed cancellation, making the test deterministic on slow activation paths.
test/Grains/TestGrains/GenericGrains.cs Adds a grain method which notifies an observer that execution has started, then calls the existing long-wait path.
test/Grains/TestGrainInterfaces/IGenericInterfaces.cs Adds a test observer interface and a new grain method signature to support the start-notification handshake.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

@ReubenBond
ReubenBond merged commit 907a72a into dotnet:main Aug 1, 2026
66 of 67 checks passed
@ReubenBond
ReubenBond deleted the reubenbond-fix-cancellation-liveness-race branch August 1, 2026 14:31
This was referenced Aug 28, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 1, 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