Repository navigation
Isolate test registration callback failures #7556
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using Shouldly; | ||
| using TUnit.Engine.Tests.Enums; | ||
|
|
||
| namespace TUnit.Engine.Tests; | ||
|
|
||
| public class RegistrationFailure7525Tests(TestMode testMode) : InvokableTestBase(testMode) | ||
| { | ||
| [Test] | ||
| [Arguments("RegistrationFailureTests", 3, 1)] | ||
| [Arguments("ParallelRegistrationFailureTests", 8, 6)] | ||
| public async Task RegistrationFailureDoesNotAbortRequest(string className, int total, int passed) | ||
| { | ||
| await RunTestsWithFilter($"/*/TUnit.TestProject.Bugs._7525/{className}/*", | ||
| [ | ||
| result => result.ResultSummary.Counters.Total.ShouldBe(total), | ||
| result => result.ResultSummary.Counters.Failed.ShouldBe(2), | ||
| result => result.ResultSummary.Counters.Passed.ShouldBe(passed), | ||
| result => result.Results.Where(x => x.Outcome == "Failed") | ||
| .ShouldAllBe(x => x.Output!.ErrorInfo!.Message!.Contains("Registration ") | ||
| && x.Output.ErrorInfo.Message.Contains("failed (#7525)")) | ||
| ]); | ||
| } | ||
| [Test] | ||
| public async Task RegistrationFailureDisposesExistingArguments() | ||
| { | ||
| await RunTestsWithFilter("/*/TUnit.TestProject.Bugs._7525/RegistrationDisposalTests/*", | ||
| [ | ||
| result => result.ResultSummary.Counters.Total.ShouldBe(2), | ||
| result => result.ResultSummary.Counters.Failed.ShouldBe(1), | ||
| result => result.ResultSummary.Counters.Passed.ShouldBe(1), | ||
| result => result.Results.Single(x => x.Outcome == "Failed").Output!.ErrorInfo!.Message! | ||
| .ShouldContain("Registration receiver failed (#7525)") | ||
| ]); | ||
| } | ||
| } |
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,79 @@ | ||
| using TUnit.Core.Interfaces; | ||
| using TUnit.TestProject.Attributes; | ||
|
|
||
| namespace TUnit.TestProject.Bugs._7525; | ||
|
|
||
| public class RegistrationFailureTests | ||
| { | ||
| public sealed class ThrowingReceiverAttribute : Attribute, ITestRegisteredEventReceiver | ||
| { | ||
| public int Order => 0; | ||
|
|
||
| public ValueTask OnTestRegistered(TestRegisteredContext context) | ||
| { | ||
| context.SetSkipped("skip before registration failure"); | ||
| throw new InvalidOperationException("Registration receiver failed (#7525)"); | ||
| } | ||
| } | ||
|
|
||
| public sealed class ThrowingDelegateAttribute : DataSourceGeneratorAttribute<int> | ||
| { | ||
| protected override IEnumerable<Func<int>> GenerateDataSources(DataGeneratorMetadata metadata) | ||
| { | ||
| yield return () => | ||
| { | ||
| metadata.TestBuilderContext.Current.Events.OnTestRegistered += async (_, _) => | ||
| { | ||
| await Task.Yield(); | ||
| throw new InvalidOperationException("Registration delegate failed (#7525)"); | ||
| }; | ||
| return 1; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| [Test, ThrowingReceiver, EngineTest(ExpectedResult.Failure)] | ||
| public void ReceiverFailure() => throw new Exception("Test body must not execute"); | ||
|
|
||
| [Test, ThrowingDelegate, EngineTest(ExpectedResult.Failure)] | ||
| public void DelegateFailure(int value) => throw new Exception("Test body must not execute"); | ||
|
|
||
| [Test, EngineTest(ExpectedResult.Pass)] | ||
| public void UnrelatedTest() { } | ||
| } | ||
|
|
||
| // Eight or more tests take the parallel registration path. | ||
| [InheritsTests] | ||
| public class ParallelRegistrationFailureTests : RegistrationFailureTests | ||
| { | ||
| [Test, Arguments(1), Arguments(2), Arguments(3), Arguments(4), Arguments(5), EngineTest(ExpectedResult.Pass)] | ||
| public void OtherTests(int value) { } | ||
| } | ||
|
|
||
| public sealed class RegistrationDisposable : IDisposable | ||
| { | ||
| public static List<RegistrationDisposable> Created { get; } = []; | ||
| public bool IsDisposed { get; private set; } | ||
| public RegistrationDisposable() => Created.Add(this); | ||
| public IAsyncInitializer Child => throw new InvalidOperationException("tracking getter failed"); | ||
| public void Dispose() => IsDisposed = true; | ||
| } | ||
|
|
||
| [EngineTest(ExpectedResult.Failure)] | ||
| public class RegistrationDisposalTests | ||
| { | ||
| public static IEnumerable<RegistrationDisposable> Values() | ||
| { | ||
| yield return new RegistrationDisposable(); | ||
| } | ||
|
|
||
| [Test, RegistrationFailureTests.ThrowingReceiver, MethodDataSource(nameof(Values))] | ||
| public void Fails(RegistrationDisposable value) => throw new Exception("Test body must not execute"); | ||
|
|
||
| [Test, DependsOn(nameof(Fails), ProceedOnFailure = true)] | ||
| public async Task ArgumentWasDisposed() | ||
| { | ||
| await Assert.That(RegistrationDisposable.Created.Count).IsEqualTo(1); | ||
| await Assert.That(RegistrationDisposable.Created[0].IsDisposed).IsTrue(); | ||
| } | ||
| } |
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.