-
-
Couldn't load subscription status.
- Fork 94
Fix dependency injection scope sharing between test executions #2931
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
Conversation
Co-authored-by: thomhurst <[email protected]>
Co-authored-by: thomhurst <[email protected]>
Co-authored-by: thomhurst <[email protected]>
…nflicts Co-authored-by: thomhurst <[email protected]>
|
@copilot Add a test for this, and decorate it with [EngineTest(ExpectedResult.Pass)] so it is run as part of the regression |
Co-authored-by: thomhurst <[email protected]>
Head branch was pushed to by a user without write access
Added regression test |
When using
DependencyInjectionDataSourceAttribute<TScope>with multiple test arguments, the same dependency injection scope was incorrectly shared across all test invocations, causing scoped services to be reused when they should be isolated per test.Problem
Consider this test class using dependency injection:
Before this fix: Both test executions would output
1because they shared the same DI scope and got the sameDependencyinstance.After this fix: The test executions output different values (
1and2or2and1) because each gets its own DI scope with a freshDependencyinstance.Solution
The issue was in
DependencyInjectionDataSourceAttribute<TScope>.GenerateDataSources()where the scope was created once during data generation and reused across all test executions:Changed to create a new scope for each test execution:
This ensures proper test isolation while maintaining backward compatibility. Each scope is properly disposed after its corresponding test execution through the test context's disposal events.
Fixes #2930.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.