Skip to content

DependencyInjectionDataSourceAttribute scopes are never disposed: builder-context events never reach the test #7205

Closed
3 of 3 issues completed

Description

@thomhurst

Summary

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.

Remaining work

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/main d8badac, 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.

Activity

  1. added
    P1High: significant user-facing bug, fix soon
    on Oct 31, 2026
  2. 35 remaining items

  3. thomhurst commented on Nov 3, 2026

    @thomhurst
    OwnerAuthor

    All three native sub-issues are closed. Audited the parent's acceptance criteria against freshly fetched origin/main at f2118034282df594298b9b71005fc4a9149f3d07; no implementation remains.

    Fresh local validation on that main commit, SDK 10.0.403 / net10.0 / macOS arm64, in both source-generated and reflection modes:

    Targeted filter Result in each mode
    /*/TUnit.TestProject.Bugs._7205/*/* 25 total: 17 passed, 5 intentional failures, 3 skipped; matches Issue7205Tests exactly
    /*/TUnit.UnitTests/*CleanupTests/* 29 passed (deferred discovery, generic partition and static handler cleanup)
    /*/TUnit.UnitTests/StaticPropertyScopeDisposalTests/* 2 passed
    /*/TUnit.UnitTests/ExternallyOwnedSingletonTests/* 4 passed

    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.

    Closing as implemented by #7384 and #7459.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High: significant user-facing bug, fix soonbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions