-
-
Notifications
You must be signed in to change notification settings - Fork 111
fix: populate dependencies before After(TestDiscovery) hooks #4606
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 1 commit into
main
from
fix/4584-dependencies-in-after-test-discovery-hook
Jan 29, 2026
Merged
fix: populate dependencies before After(TestDiscovery) hooks #4606
thomhurst
merged 1 commit into
main
from
fix/4584-dependencies-in-after-test-discovery-hook
Jan 29, 2026
Conversation
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
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
c388845 to
d84f409
Compare
d84f409 to
05e6385
Compare
05e6385 to
0f13b50
Compare
0f13b50 to
cccdbe4
Compare
This fixes two issues: 1. Dependencies were not available in After(TestDiscovery) hooks because PopulateDependencies was called during per-test registration, after hooks. Now dependencies are populated for ALL tests before hooks run. 2. OnTestRegistered was being called twice - once in InvokePostResolutionEventsAsync (for all tests) and again in TestFilterService.RegisterTest (for filtered tests). Now OnTestRegistered only fires once, in TestFilterService.RegisterTest, which is the correct semantic: registration events fire for tests that will run. Changes: - Add _dependenciesPopulated flag to TestContext for idempotent population - Add PopulateDependenciesOnly() to ITestBuilder/TestBuilder - Add PopulateAllDependencies() to TestBuilderPipeline - Call PopulateAllDependencies() before After(TestDiscovery) hooks - Remove InvokeTestRegisteredReceiversAsync from InvokePostResolutionEventsAsync (discovery events still fire for all tests, registration events for filtered only)
cccdbe4 to
1970efa
Compare
This was referenced Jan 29, 2026
This was referenced Jan 29, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #4584
This PR fixes two issues:
Issue 1: Dependencies not available in
After(TestDiscovery)hooksDependencies were not populated when
After(TestDiscovery)hooks ran becausePopulateDependencieswas called during the per-test registration loop, which happens after hooks execute.Fix: Populate
TestContext._dependenciesfor ALL tests beforeAfter(TestDiscovery)hooks run.Issue 2:
OnTestRegisteredcalled twice (bug discovered during investigation)ITestRegisteredEventReceiver.OnTestRegisteredwas being called twice:InvokePostResolutionEventsAsyncfor ALL testsTestFilterService.RegisterTestfor FILTERED testsThis caused indeterministic behavior - the first call saw empty dependencies (before population), made a skip decision, then the second call saw populated dependencies but the decision was already made.
Fix: Remove
OnTestRegisteredfromInvokePostResolutionEventsAsync. Registration events now only fire inTestFilterService.RegisterTestfor filtered tests. This is semantically correct:OnTestDiscovered) → ALL testsOnTestRegistered) → FILTERED tests only (tests that will run)Changes
TestContext.Dependencies.cs: Add_dependenciesPopulatedflag for idempotent populationITestBuilder.cs: AddPopulateDependenciesOnly()methodTestBuilder.cs:PopulateDependenciesOnly()with idempotencyInvokeTestRegisteredReceiversAsync()fromInvokePostResolutionEventsAsync()InvokeTestRegisteredReceiversAsync()methodTestBuilderPipeline.cs: AddPopulateAllDependencies()batch methodTestDiscoveryService.cs: CallPopulateAllDependencies()beforeAfter(TestDiscovery)hooksTestFilterService.cs: AddInvalidateDisplayNameCache()after registration events (moved from removed code)Test plan
TUnit.TestProject/Bugs/4584/FocusAssemblyAttribute)