Skip to content

Flow CancellationToken through durable jobs tests#9909

Merged
ReubenBond merged 2 commits into
mainfrom
copilot/add-flow-cancellationtoken-tests
Feb 16, 2026
Merged

Flow CancellationToken through durable jobs tests#9909
ReubenBond merged 2 commits into
mainfrom
copilot/add-flow-cancellationtoken-tests

Conversation

Copilot AI commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Durable jobs tests had no per-test timeout mechanism. Operations used CancellationToken.None or local short-lived CancellationTokenSource instances, meaning a hung test would block indefinitely.

Changes

  • DurableJobTestsRunner — Accept CancellationToken on all public methods. Replace .WithTimeout() with .WaitAsync(cancellationToken) on grain calls so cancellation is observed at every await point.
  • JobShardManagerTestsRunner — Accept CancellationToken on all public methods. Replace all CancellationToken.None with the passed token. Remove local timeout-only CancellationTokenSource instances (the test-level token now serves this role). Use CreateLinkedTokenSource where a shorter sub-timeout is still needed (e.g., verifying an empty shard).
  • Test wrappers (InMemoryDurableJobsTests, InMemoryJobShardManagerTests, AzureStorageBlobDurableJobsTests, AzureStorageJobShardManagerTests, AzureStorageJobShardBatchingTests) — Each test method creates a 2-minute CancellationTokenSource and passes the token to the runner.

Example

Before:

[Fact, TestCategory("BVT"), TestCategory("DurableJobs")]
public Task DurableJobGrain()
    => _runner.DurableJobGrain();

After:

[Fact, TestCategory("BVT"), TestCategory("DurableJobs")]
public async Task DurableJobGrain()
{
    using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2));
    await _runner.DurableJobGrain(cts.Token);
}

Runner methods flow the token to all async operations:

var job = await grain.ScheduleJobAsync("TestJob", dueTime).WaitAsync(cancellationToken);
await grain.WaitForJobToRun(job.Id).WaitAsync(cancellationToken);

Note: xUnit v2 does not support CancellationToken injection on [Fact] methods, so the token is created inside each test method rather than accepted as a parameter.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Microsoft Reviewers: Open in CodeFlow

Copilot AI changed the title [WIP] Add Flow CancellationToken for durable jobs tests Flow CancellationToken through durable jobs tests Feb 12, 2026
Copilot AI requested a review from benjaminpetit February 12, 2026 13:28
@benjaminpetit benjaminpetit mentioned this pull request Feb 12, 2026
14 tasks
@ReubenBond ReubenBond force-pushed the copilot/add-flow-cancellationtoken-tests branch from 975ceb3 to ca5c062 Compare February 15, 2026 17:23
@ReubenBond ReubenBond marked this pull request as ready for review February 15, 2026 17:24
Copilot AI review requested due to automatic review settings February 15, 2026 17:24
@ReubenBond ReubenBond enabled auto-merge February 15, 2026 17:24

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 adds per-test timeout mechanisms to durable jobs tests by flowing CancellationToken throughout the test infrastructure. Previously, tests used CancellationToken.None or local short-lived CancellationTokenSource instances, meaning hung tests could block indefinitely. The changes ensure every async operation in durable jobs tests can be cancelled via a test-level timeout.

Changes:

  • Test runners (DurableJobTestsRunner and JobShardManagerTestsRunner) now accept CancellationToken on all public methods and flow it through all async operations using .WaitAsync(cancellationToken) instead of .WithTimeout()
  • All test wrappers create a 2-minute CancellationTokenSource per test method and pass the token to runners
  • Local timeout-only CancellationTokenSource instances removed in favor of the test-level token, with CreateLinkedTokenSource used where shorter sub-timeouts are needed

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/Tester/DurableJobs/JobShardManagerTestsRunner.cs Added CancellationToken parameters to all test methods, replaced CancellationToken.None with passed token, removed local timeout-only CTS instances, used CreateLinkedTokenSource for sub-timeouts
test/Tester/DurableJobs/InMemoryJobShardManagerTests.cs Wrapped each test to create 2-minute CTS and pass token to runner
test/Tester/DurableJobs/DurableJobTestsRunner.cs Added CancellationToken parameters, replaced .WithTimeout() with .WaitAsync(cancellationToken), removed unused Orleans.Internal import
test/Extensions/TesterAzureUtils/DurableJobs/AzureStorageJobShardManagerTests.cs Wrapped each test to create 2-minute CTS and pass token to runner
test/Extensions/TesterAzureUtils/DurableJobs/AzureStorageJobShardBatchingTests.cs Added 2-minute CTS creation and flowed token through all operations
test/Extensions/TesterAzureUtils/DurableJobs/AzureStorageBlobDurableJobsTests.cs Wrapped each test to create 2-minute CTS and pass token to runner
test/DefaultCluster.Tests/InMemoryDurableJobsTests.cs Wrapped each test to create 2-minute CTS and pass token to runner

@ReubenBond ReubenBond disabled auto-merge February 15, 2026 20:59
@ReubenBond ReubenBond added this pull request to the merge queue Feb 15, 2026
@ReubenBond ReubenBond removed this pull request from the merge queue due to a manual request Feb 15, 2026
@ReubenBond ReubenBond added this pull request to the merge queue Feb 15, 2026
@ReubenBond ReubenBond removed this pull request from the merge queue due to a manual request Feb 15, 2026
Copilot AI and others added 2 commits February 16, 2026 09:29
Add CancellationToken parameter to all DurableJobTestsRunner and
JobShardManagerTestsRunner public methods. Replace CancellationToken.None
with the passed token in JobShardManagerTestsRunner. Remove local
CancellationTokenSource instances where they are no longer needed.

Create CancellationTokenSource with 2-minute timeout in each test
method and pass the token to the runner methods. This applies to:
- InMemoryDurableJobsTests
- InMemoryJobShardManagerTests
- AzureStorageBlobDurableJobsTests
- AzureStorageJobShardManagerTests
- AzureStorageJobShardBatchingTests

Co-authored-by: benjaminpetit <20427417+benjaminpetit@users.noreply.github.com>
… cancellation token

Replace .WithTimeout() calls with .WaitAsync(cancellationToken) on all
grain interface calls so the cancellation token is actively observed.
This ensures the 2-minute test timeout properly cancels hung operations.

Co-authored-by: benjaminpetit <20427417+benjaminpetit@users.noreply.github.com>
@ReubenBond ReubenBond force-pushed the copilot/add-flow-cancellationtoken-tests branch from ca5c062 to 436f30f Compare February 16, 2026 17:30
@ReubenBond ReubenBond enabled auto-merge February 16, 2026 17:50
@ReubenBond ReubenBond added this pull request to the merge queue Feb 16, 2026
Merged via the queue into main with commit 9cdf008 Feb 16, 2026
112 of 113 checks passed
@ReubenBond ReubenBond deleted the copilot/add-flow-cancellationtoken-tests branch February 16, 2026 22:48
rkargMsft pushed a commit to rkargMsft/orleans that referenced this pull request Feb 27, 2026
* Flow CancellationToken through durable jobs tests with 2-minute timeout

Add CancellationToken parameter to all DurableJobTestsRunner and
JobShardManagerTestsRunner public methods. Replace CancellationToken.None
with the passed token in JobShardManagerTestsRunner. Remove local
CancellationTokenSource instances where they are no longer needed.

Create CancellationTokenSource with 2-minute timeout in each test
method and pass the token to the runner methods. This applies to:
- InMemoryDurableJobsTests
- InMemoryJobShardManagerTests
- AzureStorageBlobDurableJobsTests
- AzureStorageJobShardManagerTests
- AzureStorageJobShardBatchingTests

Co-authored-by: benjaminpetit <20427417+benjaminpetit@users.noreply.github.com>

* Use .WaitAsync(cancellationToken) in DurableJobTestsRunner to observe cancellation token

Replace .WithTimeout() calls with .WaitAsync(cancellationToken) on all
grain interface calls so the cancellation token is actively observed.
This ensures the 2-minute test timeout properly cancels hung operations.

Co-authored-by: benjaminpetit <20427417+benjaminpetit@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: benjaminpetit <20427417+benjaminpetit@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 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.

4 participants