Repository navigation
fix(engine): report every test once on fail-fast runs #7145
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
52 changes: 52 additions & 0 deletions
52
tests/TUnit.Engine.Tests/Scheduling/FailFastReportingTests.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,52 @@ | ||
| using Shouldly; | ||
| using TUnit.Engine.Tests.Enums; | ||
|
|
||
| namespace TUnit.Engine.Tests.Scheduling; | ||
|
|
||
| /// <summary> | ||
| /// #7119: on a --fail-fast run every selected test must get exactly one result node. Tests that | ||
| /// fail-fast stops before they start are reported as skipped, and the failure that triggered | ||
| /// fail-fast is not reported a second time as an "Unhandled exception" node when the | ||
| /// unconstrained and keyed phases were running at the same time. A test that failed before it | ||
| /// ran (data source error) and that fail-fast stopped is still reported as failed. | ||
| /// </summary> | ||
| public class FailFastReportingTests(TestMode testMode) : InvokableTestBase(testMode) | ||
| { | ||
| private static readonly string[] TestNames = | ||
| ["Fails", "Parallel1", "Parallel2", "Keyed1", "Keyed2", "Global1", "Global2", "DataSourceFails"]; | ||
|
|
||
| [Test] | ||
| public async Task FailFast_ReportsEveryTestOnce_AndCancelledTestsAsSkipped() | ||
| { | ||
| using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); | ||
| var process = new ProcessResultCapture(); | ||
|
|
||
| await RunTestsWithFilter("/*/*/FailFastReporting7119/*", | ||
| [ | ||
| _ => process.AssertEndedWithoutCrash(), | ||
| result => result.ResultSummary.Outcome.ShouldBe("Failed"), | ||
| result => result.Results.ShouldNotContain( | ||
| x => x.TestName!.StartsWith("Unhandled exception", StringComparison.Ordinal), | ||
| "The fail-fast failure was reported a second time as an 'Unhandled exception' node"), | ||
| result => result.Results.Select(x => x.TestName).OrderBy(x => x).ShouldBe(TestNames.OrderBy(x => x)), | ||
| result => result.Results.Single(x => x.TestName == "Fails").Outcome.ShouldBe("Failed"), | ||
| // Its data source throws, so it is failed before it runs. Fail-fast stops it before it | ||
| // reaches the coordinator, so only the cancelled-run sweep can report it. | ||
| result => result.Results.Single(x => x.TestName == "DataSourceFails").Outcome.ShouldBe("Failed"), | ||
| result => result.ResultSummary.Counters.Failed.ShouldBe(2), | ||
| // Fails runs no later than second, so fail-fast stops at least the two global | ||
| // [NotInParallel] tests and the tests still waiting for the single slot. | ||
| result => result.Results.Where(x => x.TestName is not ("Fails" or "DataSourceFails")) | ||
| .ShouldAllBe(x => x.Outcome == "Passed" || x.Outcome == "NotExecuted"), | ||
| result => result.Results.Count(x => x.Outcome == "NotExecuted").ShouldBeGreaterThanOrEqualTo(4), | ||
| result => result.Results.Where(x => x.TestName!.StartsWith("Global", StringComparison.Ordinal)) | ||
| .ShouldAllBe(x => x.Outcome == "NotExecuted"), | ||
| ], | ||
| new RunOptions() | ||
| .WithArgument("--fail-fast") | ||
| .WithArgument("--maximum-parallel-tests") | ||
| .WithArgument("1") | ||
| .WithForcefulCancellationToken(cts.Token) | ||
| .Capture(process)); | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
tests/TUnit.TestProject/Bugs/_7119/FailFastReporting7119.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,38 @@ | ||
| using TUnit.Core.Enums; | ||
| using TUnit.TestProject.Attributes; | ||
|
|
||
| namespace TUnit.TestProject.Bugs._7119; | ||
|
|
||
| /// <summary> | ||
| /// Run with --fail-fast and --maximum-parallel-tests 1. The unconstrained and keyed phases run | ||
| /// at the same time and share the single slot, so Fails (Critical priority, first in the | ||
| /// unconstrained phase) runs no later than second. Fail-fast then cancels the tests still | ||
| /// waiting for the slot, and the global [NotInParallel] phase never starts. Each test must be | ||
| /// reported exactly once: Fails as failed, every test fail-fast stopped as skipped, and no | ||
| /// extra "Unhandled exception" node for the failure. DataSourceFails fails while its data is | ||
| /// generated, so it is already failed before it runs; fail-fast stops it before it reaches the | ||
| /// coordinator, and it must still be reported as failed. | ||
| /// </summary> | ||
| [EngineTest(ExpectedResult.Failure)] | ||
| public class FailFastReporting7119 | ||
| { | ||
| [Test, ExecutionPriority(Priority.Critical)] | ||
| public void Fails() => throw new InvalidOperationException("Intentional failure to trigger fail-fast (#7119)"); | ||
|
|
||
| [Test] public Task Parallel1() => Task.Delay(100); | ||
| [Test] public Task Parallel2() => Task.Delay(100); | ||
|
|
||
| [Test, NotInParallel("7119.keyed")] public Task Keyed1() => Task.Delay(100); | ||
| [Test, NotInParallel("7119.keyed")] public Task Keyed2() => Task.Delay(100); | ||
|
|
||
| [Test, NotInParallel] public Task Global1() => Task.Delay(100); | ||
| [Test, NotInParallel] public Task Global2() => Task.Delay(100); | ||
|
|
||
| public static IEnumerable<int> ThrowingData() => | ||
| throw new InvalidOperationException("Intentional data source failure (#7119)"); | ||
|
|
||
| [Test, MethodDataSource(nameof(ThrowingData))] | ||
| public void DataSourceFails(int value) | ||
| { | ||
| } | ||
| } |
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.