Repository navigation
fix(core): keep the engine-selected execution mode when late assemblies load #7091
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
7 commits
Select commit
Hold shift + click to select a range
39e5029
fix(core): keep the engine-selected execution mode when late assembli…
thomhurst 6a1ee52
fix(core): document and trace ignored SourceRegistrar.IsEnabled writes
thomhurst b1451ee
Merge remote-tracking branch 'origin/main' into fix/sourceregistrar-i…
thomhurst 1c20e61
docs(core): note that a later LockExecutionMode call replaces the loc…
thomhurst aabb4b4
Merge remote-tracking branch 'origin/main' into fix/sourceregistrar-i…
thomhurst 3491deb
fix(core): track source-generation availability separately from the l…
thomhurst 88e7d76
test: refresh Tests7096 snapshot for methodTypeArgumentsIdentity from…
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
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,20 @@ | ||
| using Shouldly; | ||
| using TUnit.Engine.Tests.Enums; | ||
|
|
||
| namespace TUnit.Engine.Tests; | ||
|
|
||
| public class Issue7089Tests(TestMode testMode) : InvokableTestBase(testMode) | ||
| { | ||
| [Test] | ||
| public async Task Late_IsEnabled_Write_Does_Not_Change_Selected_Mode() | ||
| { | ||
| await RunTestsWithFilter( | ||
| "/*/TUnit.TestProject.Bugs._7089/ExecutionModeLockTests/*", | ||
| [ | ||
| result => result.ResultSummary.Outcome.ShouldBe("Completed"), | ||
| result => result.ResultSummary.Counters.Total.ShouldBe(1), | ||
| result => result.ResultSummary.Counters.Passed.ShouldBe(1), | ||
| result => result.ResultSummary.Counters.Failed.ShouldBe(0), | ||
| ]); | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
tests/TUnit.TestProject/Bugs/7089/ExecutionModeLockTests.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,42 @@ | ||
| using TUnit.Core.Services; | ||
| using TUnit.TestProject.Attributes; | ||
|
|
||
| namespace TUnit.TestProject.Bugs._7089; | ||
|
|
||
| /// <summary> | ||
| /// Regression test for #7089: the generated module initializer of an assembly that loads mid-run | ||
| /// writes <c>SourceRegistrar.IsEnabled = true</c>. That write must not change the execution mode | ||
| /// the engine already selected. | ||
| /// </summary> | ||
| [EngineTest(ExpectedResult.Pass)] | ||
| public class ExecutionModeLockTests | ||
| { | ||
| [Test] | ||
| public async Task Late_IsEnabled_Write_Does_Not_Change_Selected_Mode() | ||
| { | ||
| // The engine has already selected and locked the mode by the time a test runs. Capture it | ||
| // rather than inferring it from the command line, which is only one way to select it. | ||
| var selectedSourceGeneration = SourceRegistrar.IsEnabled; | ||
| var sourceGenerationAvailable = ModeDetector.IsSourceGenerationAvailable; | ||
|
|
||
| try | ||
| { | ||
| // What a late-loading assembly's generated module initializer does. The write must not | ||
| // change the selected mode, but it must still record that source generation is | ||
| // available, so a later engine instance in the process can fall back to it. | ||
| SourceRegistrar.IsEnabled = true; | ||
| await Assert.That(SourceRegistrar.IsEnabled).IsEqualTo(selectedSourceGeneration); | ||
| await Assert.That(ModeDetector.IsSourceGenerationAvailable).IsTrue(); | ||
|
|
||
| SourceRegistrar.IsEnabled = false; | ||
| await Assert.That(SourceRegistrar.IsEnabled).IsEqualTo(selectedSourceGeneration); | ||
| await Assert.That(ModeDetector.IsSourceGenerationAvailable).IsFalse(); | ||
| } | ||
| finally | ||
| { | ||
| // Without the fix the writes above stick. Once the mode is locked this write only | ||
| // restores the availability signal; the selected mode stays as it is. | ||
| SourceRegistrar.IsEnabled = sourceGenerationAvailable; | ||
| } | ||
| } | ||
| } |
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
19 changes: 19 additions & 0 deletions
19
tests/TUnit.UnitTests/SourceRegistrarExecutionModeTests.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,19 @@ | ||
| namespace TUnit.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// Regression test for #7089. This project references TUnit.Playwright, which is built with the | ||
| /// source generator. In reflection mode its generated module initializer first runs during | ||
| /// discovery, after the engine has selected the mode, and used to set | ||
| /// <see cref="SourceRegistrar.IsEnabled"/> back to <c>true</c>. Closed generic test classes then | ||
| /// failed with "Cannot use reflection-based hook discovery when source generation is enabled". | ||
| /// Run this project with and without <c>--reflection</c> to cover both modes. | ||
| /// </summary> | ||
| [GenerateGenericTest(typeof(int))] | ||
| public class SourceRegistrarExecutionModeGenericTests<T> | ||
| { | ||
| [Test] | ||
| public async Task Closed_Generic_Test_Class_Runs() | ||
| { | ||
| await Assert.That(typeof(T)).IsEqualTo(typeof(int)); | ||
| } | ||
| } |
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.