You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DependencyInjectionDataSourceAttribute scopes are never disposed: builder-context events never reach the test #7205
Dependency-injection scopes subscribe cleanup on a data row's builder context, but that context's events do not reach the test. Scopes therefore leak in both source-generated and reflection modes. The fix is split into the native sub-issues below; this issue tracks their combined outcome.
PR #7384 currently delivers #7381 and #7382. PR #7328 was closed without merging and is superseded by this split. Failed-row event delivery is tracked separately in #7326.
Evidence
On origin/maind8badac, DependencyInjectionDataSourceAttribute<TScope> registers OnDispose in src/TUnit.Core/Attributes/TestData/DependencyInjectionDataSourceSourceAttribute.cs. TestBuilder shares row state bags but not row events with test-specific contexts. TestCoordinator.DisposeTestInstanceCoreAsync still raises the test context's callbacks per attempt. ShareEventsWith and the once-per-test raiser have not landed.
Acceptance criteria
Per-test scopes are disposed exactly once after the final attempt; retries do not observe disposed services and repeats have separate scopes.
Scope-owned services are disposed exactly once, while non-disposable scopes retain tracker disposal.
Session-lifetime scopes remain valid while shared and are disposed once at session end, even when no test executes.
Validate each lifetime in both metadata modes, as specified by the sub-issues.
All three native sub-issues are closed. Audited the parent's acceptance criteria against freshly fetched origin/main at f2118034282df594298b9b71005fc4a9149f3d07; no implementation remains.
Session lifetime, including no executed tests: merged PR fix: dispose session-lifetime DI scopes at session end #7459 (374bb7c0aa750268d731f8241acf31a34dbb3025) retains static-property, generic-partition, temporary-instance property and lent-constructor callbacks until session cleanup. Both metadata modes have the plumbing; session-finally/provider-disposal paths drain discovery callbacks even without test execution. Static leases keep shared fixtures and scopes alive until their final owning session releases them.
Fresh local validation on that main commit, SDK 10.0.403 / net10.0 / macOS arm64, in both source-generated and reflection modes:
Commands used dotnet test --project <project> --framework net10.0 --treenode-filter '<filter>', repeated with --reflection (and --no-build after building each project). The _7205 commands intentionally exit 2: the five failures exercise failed dependencies, circular dependencies and invalid generic rows. Its disposal observer passes, and the three borrowed-service method rows pass.
Both merged PRs have successful modularpipeline checks on macOS, Ubuntu and Windows. TUnit.Engine.Tests was not run locally, per repository instructions. No code, public API or generator output changed during this audit; no new AOT publish was needed or run. Broader failed-row event delivery remains separately tracked in #7326, as already scoped by this issue.
Activity
fix(engine): raise OnDispose once per test, after retries and on skip…
fix(engine): deliver builder-context events to the test built from ea…
fix(engine): raise OnDispose once per test, after retries and on skip…
fix(engine): leave services a DI scope owns to that scope, not the ob…
fix(engine): dispose failed rows' scopes and leave unowned DI service…
fix(engine): leave initializer objects held by DI-scoped services to …
fix(core): keep TUnit-injected properties tracker-owned beneath a sco…
chore(core): drop the BOM the PR added to ObjectTracker.cs (#7205)
fix(engine): deliver builder-context events to the test built from ea…
fix(engine): raise OnDispose once per test, after retries and on skip…
fix(engine): leave services a DI scope owns to that scope, not the ob…
fix(engine): dispose failed rows' scopes and leave unowned DI service…
35 remaining items
fix(engine): deliver row builder-context events to the test and raise…
thomhurst commentedon Nov 3, 2026
All three native sub-issues are closed. Audited the parent's acceptance criteria against freshly fetched
origin/mainatf2118034282df594298b9b71005fc4a9149f3d07; no implementation remains.87d2a3051a0352fe96ee1faae1ff146c1602b309) shares row events with test contexts in both metadata paths and raisesOnDisposeonce in final cleanup, including scheduler exits. The retry keeps its services alive; each repeat has its own scope.374bb7c0aa750268d731f8241acf31a34dbb3025) retains static-property, generic-partition, temporary-instance property and lent-constructor callbacks until session cleanup. Both metadata modes have the plumbing; session-finally/provider-disposal paths drain discovery callbacks even without test execution. Static leases keep shared fixtures and scopes alive until their final owning session releases them.Fresh local validation on that main commit, SDK 10.0.403 / net10.0 / macOS arm64, in both source-generated and reflection modes:
/*/TUnit.TestProject.Bugs._7205/*/*Issue7205Testsexactly/*/TUnit.UnitTests/*CleanupTests/*/*/TUnit.UnitTests/StaticPropertyScopeDisposalTests/*/*/TUnit.UnitTests/ExternallyOwnedSingletonTests/*Commands used
dotnet test --project <project> --framework net10.0 --treenode-filter '<filter>', repeated with--reflection(and--no-buildafter building each project). The_7205commands intentionally exit 2: the five failures exercise failed dependencies, circular dependencies and invalid generic rows. Its disposal observer passes, and the three borrowed-service method rows pass.Both merged PRs have successful modularpipeline checks on macOS, Ubuntu and Windows.
TUnit.Engine.Testswas not run locally, per repository instructions. No code, public API or generator output changed during this audit; no new AOT publish was needed or run. Broader failed-row event delivery remains separately tracked in #7326, as already scoped by this issue.Closing as implemented by #7384 and #7459.