[Injection] Tie the Revit connection to the test host process - #111
Merged
Conversation
Nice3point
force-pushed
the
injection/108-tie-connection-to-process
branch
from
September 10, 2026 15:38
cfade92 to
139045e
Compare
Nice3point
force-pushed
the
injection/108-tie-connection-to-process
branch
from
September 10, 2026 15:44
e0b4532 to
41247d9
Compare
Nice3point
marked this pull request as ready for review
September 10, 2026 15:58
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.
Holds one Revit connection for the life of the test host process.
What changed
RevitApiTestopens the connection on the first session that executes a test, and a later session in the same process keeps it. Revit activates once per process, and the second session used to fail the whole run.RevitConnectionLifetime, anITestHostApplicationLifetime, releases the connection on the Revit thread after the last session of the process. The package registers it through theTestingPlatformBuilderHookitem of its build props; a consuming project needs no change, and a project with its own entry point callsAddRevit.RevitApiTest.RevitSessionCleanupis gone. It released the connection after every session.Where to look
ITestHostApplicationLifetime.BeforeRunAsyncwas the alternative for a symmetric pair, and it runs for a discovery request too, which would start Revit whenever an IDE lists the tests. The cost of the session hook is that the pair is split across two mechanisms.AfterRunAsyncand carries no timeout. A run that leaves Revit connected never terminates, and a hung eject would hang the host; a timeout would instead exit and leak. The current behaviour matches what the package already did.build/Nice3point.TUnit.Revit.propsis packed into bothbuildandbuildTransitive. Packing intobuildalone was the alternative, and it would drop the registration for a project that receives the package through a shared test library, which fails as a host that never exits.How verified
Debug.R21(net48),Debug.R26,Debug.R27andRelease.R27— zero warnings, zero errors.Debug.R24could not restoreNice3point.Revit.Injectorfrom the feed here (401), andDebug.R21covers the same target framework.Debug.R27against Revit 2027: 62 tests, zero failures, 4 skipped. The host exits about a second after the last test.run 1 finished in 4s : passed=1,run 2 finished in 0s : passed=1,server exit code 0. Ondevelopthe second run reports[Setup Failure] BeforeTestSession hook failed: Attempted to write protected memory.--list-tests: 61 tests found in 115 ms and the process exits in 1.5 s, so Revit never starts and the lifetime releases nothing.Open questions
RevitThreadExecutordeclares anIParallelLimitof1, and TUnit installs an executor without forwardingITestRegisteredEventReceiverto it, so the limit never reaches the scheduler and Revit tests interleave at everyawait. The fix is fix: preserve executor registration, limiter precedence, and timeout classification thomhurst/TUnit#6768, and the limit starts applying with the TUnit version that carries it. Measured on this branch: a test class that inheritsRevitApiTestreportsParallelism.Limiterasnull, and a suite whose tests share state acrossawaitneeds--maximum-parallel-tests 1until the update.