-
-
Notifications
You must be signed in to change notification settings - Fork 84
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 <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
…nflicts Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
@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 <30480171+thomhurst@users.noreply.github.com>
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
1
because they shared the same DI scope and got the sameDependency
instance.After this fix: The test executions output different values (
1
and2
or2
and1
) because each gets its own DI scope with a freshDependency
instance.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.