Flow CancellationToken through durable jobs tests#9909
Merged
Conversation
Copilot
AI
changed the title
[WIP] Add Flow CancellationToken for durable jobs tests
Flow CancellationToken through durable jobs tests
Feb 12, 2026
975ceb3 to
ca5c062
Compare
Contributor
There was a problem hiding this comment.
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 (
DurableJobTestsRunnerandJobShardManagerTestsRunner) now acceptCancellationTokenon all public methods and flow it through all async operations using.WaitAsync(cancellationToken)instead of.WithTimeout() - All test wrappers create a 2-minute
CancellationTokenSourceper test method and pass the token to runners - Local timeout-only
CancellationTokenSourceinstances removed in favor of the test-level token, withCreateLinkedTokenSourceused 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 |
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>
ca5c062 to
436f30f
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Durable jobs tests had no per-test timeout mechanism. Operations used
CancellationToken.Noneor local short-livedCancellationTokenSourceinstances, meaning a hung test would block indefinitely.Changes
DurableJobTestsRunner— AcceptCancellationTokenon all public methods. Replace.WithTimeout()with.WaitAsync(cancellationToken)on grain calls so cancellation is observed at every await point.JobShardManagerTestsRunner— AcceptCancellationTokenon all public methods. Replace allCancellationToken.Nonewith the passed token. Remove local timeout-onlyCancellationTokenSourceinstances (the test-level token now serves this role). UseCreateLinkedTokenSourcewhere a shorter sub-timeout is still needed (e.g., verifying an empty shard).InMemoryDurableJobsTests,InMemoryJobShardManagerTests,AzureStorageBlobDurableJobsTests,AzureStorageJobShardManagerTests,AzureStorageJobShardBatchingTests) — Each test method creates a 2-minuteCancellationTokenSourceand passes the token to the runner.Example
Before:
After:
Runner methods flow the token to all async operations:
✨ 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