Repository navigation
fix: preserve executor registration, limiter precedence, and timeout classification #6768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thomhurst
merged 6 commits into
thomhurst:main
from
Nice3point:fix/executor-test-registered-receiver
Sep 12, 2026
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e94ae82
fix: dispatch OnTestRegistered to an executor that is an event receiver
Nice3point 94dd5f5
fix: hold queued executors apart by reference, not by equality
Nice3point 9c58895
fix: preserve explicit limiter precedence and receiver identity
thomhurst 62bb050
fix: classify timeout cancellation when execution completes first
thomhurst e68c17b
fix: preserve independent cancellation during timeout races
thomhurst ceba48d
fix: classify timeouts through linked execution tokens
thomhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
82 changes: 82 additions & 0 deletions
82
tests/TUnit.TestProject/Bugs/6767/ExecutorEventReceiverTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| using TUnit.Core.Executors; | ||
| using TUnit.Core.Interfaces; | ||
| using TUnit.TestProject.Attributes; | ||
|
|
||
| namespace TUnit.TestProject.Bugs._6767; | ||
|
|
||
| /// <summary> | ||
| /// Regression test for https://github.com/thomhurst/TUnit/issues/6767 | ||
| /// An executor that also implements ITestRegisteredEventReceiver must receive | ||
| /// OnTestRegistered, so the parallel limit it declares during registration is applied. | ||
| /// </summary> | ||
| [EngineTest(ExpectedResult.Pass)] | ||
| [TestExecutor<SerialExecutor>] | ||
| public class ExecutorEventReceiverTests | ||
| { | ||
| private static int s_concurrent; | ||
| private static int s_peak; | ||
|
|
||
| [Before(Class)] | ||
| public static void Reset() | ||
| { | ||
| s_concurrent = 0; | ||
| s_peak = 0; | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task ExecutorSetsTheLimiter() | ||
| { | ||
| await Assert.That(TestContext.Current!.Parallelism.Limiter).IsTypeOf<SerialLimit>(); | ||
| } | ||
|
|
||
| [Test, Repeat(9)] | ||
| public Task Measure() => MeasureAsync(); | ||
|
|
||
| [Test, DependsOn(nameof(Measure))] | ||
| public async Task PeakIsOne() | ||
| { | ||
| await Assert.That(s_peak).IsEqualTo(1); | ||
| } | ||
|
|
||
| private static async Task MeasureAsync() | ||
| { | ||
| var current = Interlocked.Increment(ref s_concurrent); | ||
|
|
||
| int old; | ||
| do | ||
| { | ||
| old = s_peak; | ||
| if (current <= old) | ||
| { | ||
| break; | ||
| } | ||
| } | ||
| while (Interlocked.CompareExchange(ref s_peak, current, old) != old); | ||
|
|
||
| await Task.Delay(50).ConfigureAwait(false); | ||
|
|
||
| Interlocked.Decrement(ref s_concurrent); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// An executor is installed by an attribute part-way through registration, so it can only | ||
| /// declare its parallel limit through its own ITestRegisteredEventReceiver implementation. | ||
| /// </summary> | ||
| internal sealed class SerialExecutor : GenericAbstractExecutor, ITestRegisteredEventReceiver | ||
| { | ||
| public int Order => 0; | ||
|
|
||
| public ValueTask OnTestRegistered(TestRegisteredContext context) | ||
| { | ||
| context.SetParallelLimiter(new SerialLimit()); | ||
| return default; | ||
| } | ||
|
|
||
| protected override ValueTask ExecuteAsync(Func<ValueTask> action) => action(); | ||
| } | ||
|
|
||
| internal sealed class SerialLimit : IParallelLimit | ||
| { | ||
| public int Limit => 1; | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.