Conversation
…timeout When a test timed out, the cancellation callback registered by AfterHookPairTracker would fire the session-level After hooks immediately — even while other tests were still running. Additionally, TestScheduler called HookExecutor directly, bypassing the tracker's deduplication, causing hooks to run a second time. Fix by: (1) adding a first-call-wins guard so only the first RegisterAfterTestSessionHook call registers a cancellation callback (the one from TestCoordinator with the session-level token, not per-test timeout tokens), and (2) routing TestScheduler through AfterHookPairTracker.GetOrCreateAfterTestSessionTask instead of calling HookExecutor directly. Closes #4712 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Performance optimization opportunity in TestScheduler.cs line 143: The lambda creates an unnecessary ValueTask to Task to ValueTask conversion. Since GetOrCreateAfterTestSessionTask internally calls .AsTask() on the returned ValueTask, you can simplify the lambda to just: () => _hookExecutor.ExecuteAfterTestSessionHooksAsync(cancellationToken). This eliminates one allocation cycle and aligns with CLAUDE.md Rule 4 about minimizing allocations and using ValueTask appropriately. See https://github.com/thomhurst/TUnit/blob/0075a0134d8c7c5ed58d9d5820df1e20f7441293/CLAUDE.md for the rule and TUnit/TUnit.Engine/Services/AfterHookPairTracker.cs Lines 108 to 110 in 0075a01 |
…duler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 10, 2026
This was referenced Feb 11, 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
AfterHookPairTracker.RegisterAfterTestSessionHookso only the initial registration (using the session-level cancellation token) takes effect — subsequent calls from per-test timeout tokens are ignoredTestScheduler's post-execution session hook call throughAfterHookPairTracker.GetOrCreateAfterTestSessionTaskinstead of callingHookExecutordirectly, ensuring hooks execute exactly once even if a cancellation callback already triggered themAfterHookPairTrackerdependency inTUnitServiceProviderTest plan
dotnet build TUnit.sln)Closes #4712
🤖 Generated with Claude Code