Repository navigation
fix: release finished test instances before session end #7262
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using Shouldly; | ||
| using TUnit.Engine.Tests.Enums; | ||
|
|
||
| namespace TUnit.Engine.Tests; | ||
|
|
||
| /// <summary> | ||
| /// A finished test's class instance is collectable before the session ends (#7260). | ||
| /// </summary> | ||
| public class Issue7260Tests(TestMode testMode) : InvokableTestBase(testMode) | ||
| { | ||
| [Test] | ||
| public async Task Finished_Test_Instance_Is_Collectable_Before_Session_Ends() | ||
| { | ||
| await RunTestsWithFilter( | ||
| "/*/TUnit.TestProject.Bugs._7260/*/*", | ||
| [ | ||
| result => result.ResultSummary.Outcome.ShouldBe("Completed"), | ||
| result => result.ResultSummary.Counters.Total.ShouldBe(4), | ||
| result => result.ResultSummary.Counters.Passed.ShouldBe(4), | ||
| result => result.ResultSummary.Counters.Failed.ShouldBe(0) | ||
| ]); | ||
| } | ||
| } |
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
40 changes: 40 additions & 0 deletions
40
tests/TUnit.TestProject/Bugs/_7260/FinishedTestInjectedObjectReleaseTests.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,40 @@ | ||
| using TUnit.TestProject.Attributes; | ||
|
|
||
| namespace TUnit.TestProject.Bugs._7260; | ||
|
|
||
| /// <summary> | ||
| /// A per-test injected object is tracked by the test's context; once the test has finished and the | ||
| /// object has been untracked, the context must not keep it reachable either (#7260). | ||
| /// </summary> | ||
| [EngineTest(ExpectedResult.Pass)] | ||
| public class FinishedTestInjectedObjectReleaseTests | ||
| { | ||
| private static WeakReference? _finishedInjectedObject; | ||
|
|
||
| [ClassDataSource<PerTestPayload>(Shared = SharedType.None)] | ||
| public required PerTestPayload Payload { get; init; } | ||
|
|
||
| [Test] | ||
| public void Holds_Injected_Object() | ||
| { | ||
| _finishedInjectedObject = new WeakReference(Payload); | ||
| } | ||
|
|
||
| [Test] | ||
| [DependsOn(nameof(Holds_Injected_Object))] | ||
| public async Task Finished_Injected_Object_Is_Collectable() | ||
| { | ||
| await Assert.That(_finishedInjectedObject).IsNotNull(); | ||
|
|
||
| GC.Collect(); | ||
| GC.WaitForPendingFinalizers(); | ||
| GC.Collect(); | ||
|
|
||
| await Assert.That(_finishedInjectedObject!.IsAlive).IsFalse(); | ||
| } | ||
|
|
||
| public class PerTestPayload | ||
| { | ||
| public byte[] Data { get; } = new byte[1024 * 1024]; | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
tests/TUnit.TestProject/Bugs/_7260/FinishedTestInstanceReleaseTests.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,35 @@ | ||
| using TUnit.TestProject.Attributes; | ||
|
|
||
| namespace TUnit.TestProject.Bugs._7260; | ||
|
|
||
| /// <summary> | ||
| /// A finished test's class instance must not stay reachable through its TestContext, which the | ||
| /// session keeps until it ends, so state held in instance fields can be collected (#7260). | ||
| /// </summary> | ||
| [EngineTest(ExpectedResult.Pass)] | ||
| public class FinishedTestInstanceReleaseTests | ||
| { | ||
| private static WeakReference? _finishedInstance; | ||
|
|
||
| private byte[]? _payload; | ||
|
|
||
| [Test] | ||
| public void Holds_State_In_Instance_Field() | ||
| { | ||
| _payload = new byte[1024 * 1024]; | ||
| _finishedInstance = new WeakReference(this); | ||
| } | ||
|
|
||
| [Test] | ||
| [DependsOn(nameof(Holds_State_In_Instance_Field))] | ||
| public async Task Finished_Instance_Is_Collectable() | ||
| { | ||
| await Assert.That(_finishedInstance).IsNotNull(); | ||
|
|
||
| GC.Collect(); | ||
| GC.WaitForPendingFinalizers(); | ||
| GC.Collect(); | ||
|
|
||
| await Assert.That(_finishedInstance!.IsAlive).IsFalse(); | ||
| } | ||
| } |
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
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.