Add per-test execution cancellation - #6569
Merged
Merged
Conversation
Greptile SummaryThe PR adds cooperative, per-test execution cancellation and integrates it with retry transitions, timeout tokens, custom executors, documentation, and public API snapshots.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/TUnit.Core/TestContext.Execution.cs | Adds the public cancellation implementation, synchronization, retry preservation, and deferred source disposal; the previously reported races are addressed at current HEAD. |
| src/TUnit.Engine/TestExecutor.cs | Routes test execution and timeout handling through the per-test token and preserves cancellation during retryable attempt transitions. |
| src/TUnit.Engine/Services/TestExecution/RetryHelper.cs | Keeps cancellation active through retry decisions and backoff and preserves cancelled results when retry callbacks throw. |
| tests/TUnit.Engine.Tests/TestExecutionCancellationTests.cs | Adds end-to-end assertions for normal cancellation, late calls, retry backoff, retry transitions, and retry callback exceptions. |
| tests/TUnit.UnitTests/TestContextCancellationTests.cs | Adds focused synchronization tests covering deferred disposal, source replacement, and cancellation between attempts. |
| docs/docs/execution/cancellation.md | Documents cooperative test-scoped cancellation, callback usage, lifecycle behavior, and composition with existing timeout and token APIs. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Test attempt begins] --> B[Initialize per-attempt cancellation source]
B --> C[Test body / custom executor]
C --> D{Cancel requested?}
D -->|Yes| E[Signal injected and execution tokens]
D -->|No| F{Attempt failed and retryable?}
E --> G[Record Cancelled]
F -->|Yes| H[Keep cancellation open through retry decision and backoff]
H --> I[Initialize next attempt while preserving request]
I --> C
F -->|No| J[Complete cancellation acceptance]
J --> K[Finalize result and dispose sources]
G --> K
Reviews (8): Last reviewed commit: "fix(engine): close retry cancellation ga..." | Re-trigger Greptile
thomhurst
force-pushed
the
agent/test-execution-cancel
branch
from
August 8, 2026 18:52
4152d4c to
a134df5
Compare
This was referenced Aug 10, 2026
Open
github-actions Bot
pushed a commit
to BenjaminMichaelis/TrxLib
that referenced
this pull request
Aug 10, 2026
Updated [TUnit](https://github.com/thomhurst/TUnit) from 1.63.0 to 1.64.6. <details> <summary>Release notes</summary> _Sourced from [TUnit's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.64.6 <!-- Release notes generated using configuration in .github/release.yml at v1.64.6 --> ## What's Changed ### Other Changes * Switch NuGet publishing to trusted publishing by @thomhurst in thomhurst/TUnit#6573 * Expose results directory through TestContext by @thomhurst in thomhurst/TUnit#6575 * Fix outcome timeline overflow in HTML reports by @thomhurst in thomhurst/TUnit#6574 ### Dependencies * chore(deps): update tunit to 1.64.0 by @thomhurst in thomhurst/TUnit#6570 **Full Changelog**: thomhurst/TUnit@v1.64.0...v1.64.6 ## 1.64.0 <!-- Release notes generated using configuration in .github/release.yml at v1.64.0 --> ## What's Changed ### Other Changes * Honor cancellation tokens linked by custom test executors by @thomhurst in thomhurst/TUnit#6565 * Fix linked cancellation from before-test hooks by @thomhurst in thomhurst/TUnit#6568 * Add per-test execution cancellation by @thomhurst in thomhurst/TUnit#6569 ### Dependencies * chore(deps): update tunit to 1.63.25 by @thomhurst in thomhurst/TUnit#6559 * chore(deps): update dependency serialize-javascript to v7.1.0 by @thomhurst in thomhurst/TUnit#6561 * chore(deps): update dependency nsubstitute to 6.1.0 by @thomhurst in thomhurst/TUnit#6564 * chore(deps): bump mermaid from 11.15.0 to 11.16.1 in /docs by @dependabot[bot] in thomhurst/TUnit#6563 * chore(deps): bump nanoid from 3.3.16 to 3.3.18 in /docs by @dependabot[bot] in thomhurst/TUnit#6562 **Full Changelog**: thomhurst/TUnit@v1.63.25...v1.64.0 ## 1.63.25 <!-- Release notes generated using configuration in .github/release.yml at v1.63.25 --> ## What's Changed ### Other Changes * Fix Mermaid label contrast in dark mode by @thomhurst in thomhurst/TUnit#6531 * Enhance matrix tests documentation by @koryphaee in thomhurst/TUnit#6537 * fix: support nested Member after IsTypeOf by @mvanhorn in thomhurst/TUnit#6540 * docs: Add documentation for TestContext.Parameters by @thomhurst with @Copilot in thomhurst/TUnit#6558 * fix: run event receivers on injected properties by @thomhurst in thomhurst/TUnit#6556 ### Dependencies * chore(deps): update tunit to 1.63.0 by @thomhurst in thomhurst/TUnit#6526 * chore(deps): update dependency stackexchange.redis to 3.1.0 by @thomhurst in thomhurst/TUnit#6529 * chore(deps): update verify to 31.28.0 by @thomhurst in thomhurst/TUnit#6532 * chore(deps): update dependency stackexchange.redis to 3.1.3 by @thomhurst in thomhurst/TUnit#6541 * chore(deps): update dependency dompurify to v3.4.13 by @thomhurst in thomhurst/TUnit#6542 * chore(deps): update dependency rabbitmq.client to 7.2.2 by @thomhurst in thomhurst/TUnit#6546 * chore(deps): update dependency polyfill to 11.0.2 by @thomhurst in thomhurst/TUnit#6549 * chore(deps): update dependency polyfill to 11.0.2 by @thomhurst in thomhurst/TUnit#6548 * chore(deps): bump fast-uri from 3.1.4 to 3.1.5 in /docs by @dependabot[bot] in thomhurst/TUnit#6545 * chore(deps): bump postcss from 8.5.22 to 8.5.25 in /docs by @dependabot[bot] in thomhurst/TUnit#6547 * chore(deps): update dependency stackexchange.redis to 3.1.11 by @thomhurst in thomhurst/TUnit#6550 * chore(deps): update dependency stackexchange.redis to 3.1.13 by @thomhurst in thomhurst/TUnit#6552 ## New Contributors * @koryphaee made their first contribution in thomhurst/TUnit#6537 **Full Changelog**: thomhurst/TUnit@v1.63.0...v1.63.25 Commits viewable in [compare view](thomhurst/TUnit@v1.63.0...v1.64.6). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Aug 10, 2026
Open
Merged
github-actions Bot
pushed a commit
to IntelliTect/CodingGuidelines
that referenced
this pull request
Aug 10, 2026
Updated [TUnit.Core](https://github.com/thomhurst/TUnit) from 1.63.0 to 1.64.6. <details> <summary>Release notes</summary> _Sourced from [TUnit.Core's releases](https://github.com/thomhurst/TUnit/releases)._ ## 1.64.6 <!-- Release notes generated using configuration in .github/release.yml at v1.64.6 --> ## What's Changed ### Other Changes * Switch NuGet publishing to trusted publishing by @thomhurst in thomhurst/TUnit#6573 * Expose results directory through TestContext by @thomhurst in thomhurst/TUnit#6575 * Fix outcome timeline overflow in HTML reports by @thomhurst in thomhurst/TUnit#6574 ### Dependencies * chore(deps): update tunit to 1.64.0 by @thomhurst in thomhurst/TUnit#6570 **Full Changelog**: thomhurst/TUnit@v1.64.0...v1.64.6 ## 1.64.0 <!-- Release notes generated using configuration in .github/release.yml at v1.64.0 --> ## What's Changed ### Other Changes * Honor cancellation tokens linked by custom test executors by @thomhurst in thomhurst/TUnit#6565 * Fix linked cancellation from before-test hooks by @thomhurst in thomhurst/TUnit#6568 * Add per-test execution cancellation by @thomhurst in thomhurst/TUnit#6569 ### Dependencies * chore(deps): update tunit to 1.63.25 by @thomhurst in thomhurst/TUnit#6559 * chore(deps): update dependency serialize-javascript to v7.1.0 by @thomhurst in thomhurst/TUnit#6561 * chore(deps): update dependency nsubstitute to 6.1.0 by @thomhurst in thomhurst/TUnit#6564 * chore(deps): bump mermaid from 11.15.0 to 11.16.1 in /docs by @dependabot[bot] in thomhurst/TUnit#6563 * chore(deps): bump nanoid from 3.3.16 to 3.3.18 in /docs by @dependabot[bot] in thomhurst/TUnit#6562 **Full Changelog**: thomhurst/TUnit@v1.63.25...v1.64.0 ## 1.63.25 <!-- Release notes generated using configuration in .github/release.yml at v1.63.25 --> ## What's Changed ### Other Changes * Fix Mermaid label contrast in dark mode by @thomhurst in thomhurst/TUnit#6531 * Enhance matrix tests documentation by @koryphaee in thomhurst/TUnit#6537 * fix: support nested Member after IsTypeOf by @mvanhorn in thomhurst/TUnit#6540 * docs: Add documentation for TestContext.Parameters by @thomhurst with @Copilot in thomhurst/TUnit#6558 * fix: run event receivers on injected properties by @thomhurst in thomhurst/TUnit#6556 ### Dependencies * chore(deps): update tunit to 1.63.0 by @thomhurst in thomhurst/TUnit#6526 * chore(deps): update dependency stackexchange.redis to 3.1.0 by @thomhurst in thomhurst/TUnit#6529 * chore(deps): update verify to 31.28.0 by @thomhurst in thomhurst/TUnit#6532 * chore(deps): update dependency stackexchange.redis to 3.1.3 by @thomhurst in thomhurst/TUnit#6541 * chore(deps): update dependency dompurify to v3.4.13 by @thomhurst in thomhurst/TUnit#6542 * chore(deps): update dependency rabbitmq.client to 7.2.2 by @thomhurst in thomhurst/TUnit#6546 * chore(deps): update dependency polyfill to 11.0.2 by @thomhurst in thomhurst/TUnit#6549 * chore(deps): update dependency polyfill to 11.0.2 by @thomhurst in thomhurst/TUnit#6548 * chore(deps): bump fast-uri from 3.1.4 to 3.1.5 in /docs by @dependabot[bot] in thomhurst/TUnit#6545 * chore(deps): bump postcss from 8.5.22 to 8.5.25 in /docs by @dependabot[bot] in thomhurst/TUnit#6547 * chore(deps): update dependency stackexchange.redis to 3.1.11 by @thomhurst in thomhurst/TUnit#6550 * chore(deps): update dependency stackexchange.redis to 3.1.13 by @thomhurst in thomhurst/TUnit#6552 ## New Contributors * @koryphaee made their first contribution in thomhurst/TUnit#6537 **Full Changelog**: thomhurst/TUnit@v1.63.0...v1.63.25 Commits viewable in [compare view](thomhurst/TUnit@v1.63.0...v1.64.6). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Aug 10, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
TestContext.Execution.Cancel()for cooperative, test-scoped cancellationCancelledeven when the body or a custom executor consumes the cancellation exceptionPerformance
A .NET 10 microprobe measured source creation and disposal at approximately:
There is no background task, polling,
TaskCompletionSource, orTask.WhenAnyoverhead.Validation
dotnet build TUnit.Dev.slnx --no-restore -graphBuild:Truenet472,net8.0,net9.0, andnet10.0yarn typecheckremains blocked by the existing TypeScript 7baseUrlincompatibility indocs/tsconfig.json; the Docusaurus production build succeeds.Stack
Based on #6568 because its linked cancellation ownership changes are the prerequisite for composing this API with
AddLinkedCancellationTokenand[Timeout]. Retarget tomainafter #6568 merges.