Dispose a test's container when its case has run - #56
Merged
Merged
Conversation
ModuleTestCase handed each provider to the case's DisposalTracker, and xUnit disposes a test case only in InProcessFrontController.FindAndRun, after every case in the assembly has run. Every container a run built stayed alive, with every singleton in it, until the run ended. The case now executes itself and disposes what it built in a finally once its run returns, per case; NUnit's ModuleTestCommand has always done this in its own finally. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This was referenced Sep 5, 2026
ipjohnson
added a commit
that referenced
this pull request
Sep 5, 2026
Version and changelog for #56. A patch: no public API changes shape, the xUnit test case gains an interface it already satisfied in spirit. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
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
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.
What
ModuleTestCasenow implementsISelfExecutingXunitTestCase: it runs the case the way xUnit would have, throughXunitRunnerHelper.RunXunitTestCase, and disposes every provider it built in afinallyonce the run returns.Why
The provider went into the case's
DisposalTracker, and xUnit disposes a test case only inInProcessFrontController.FindAndRun, afterRunhas returned for every test case in the assembly. So every container a run built stayed alive, with every singleton in it, until the run ended. A probe in Hardened.Framework that handed three[HardenedTest]providers to an[assembly: AssemblyFixture]found all three undisposed at the end of the run. The NUnit integration has always disposed inModuleTestCommand'sfinally, and itsIterationLifetimeTestsholds it to that; nothing held xUnit to it.Hardened is about to add test hosts that bind a loopback socket per test, and a listener per test held open until the last test is the leak that has to be ruled out first.
Notes
RunTest; not done here.ContainerLifetimeTestsininteg-tests/SutProject.Testsmirrors the NUnitIterationLifetimeTests: two tests in one class, whichever runs second asserts the first's container was disposed. It fails on main (Assert.Contains() Failure: Item not found in collection: []) and passes here, on both target frameworks.Runmethod.🤖 Generated with Claude Code