Repository navigation
fix(tests): create the functional test clients under a lock - #119
Merged
Merged
Conversation
WebApplicationFactory adds each client to a List with no lock. The FunctionalTests create one client in each TestBase constructor, and TUnit runs those constructors in parallel. Two adds at the same time can lose a client or leave a null slot, and DisposeAsync then throws in the AfterAssembly hook. TestingWebApplicationFactory.CreateClient now takes a lock around the base call, the same pattern as BffApp in the Bff tests. Closes #107
Owner
Author
|
Review gate result: no high or medium finding. These low findings stay open:
The review also found a separate race on the in-memory telemetry lists. It is filed as #118. |
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.
Why
The FunctionalTests teardown sometimes failed with
AfterAssembly hook failed: Object reference not set to an instance of an objectafter every test passed.WebApplicationFactoryadds each client to aList<HttpClient>with no lock. Each test creates a client in theTestBaseconstructor, and TUnit runs those constructors in parallel. Two adds at the same time can lose a client or leave a null slot, andDisposeAsyncthen throws on the null slot.Closes #107
What changed
TestingWebApplicationFactory.CreateClient()now hides the base method and calls it under a lock.TestBasecalls it through theTestingWebApplicationFactorytype, so the lock applies.BffAppin the Bff tests.Scope
Blast Radius
Only the FunctionalTests project uses this factory. The lock serializes only the client creation. The runs took 9 to 21 seconds before the fix and 10 to 23 seconds after it, so the lock adds no time that these runs can show.
Verification
A temporary probe counted the
CreateClientcalls against the entries and null slots in the factory list at teardown. The probe is not in this PR.TestingWebApplicationFactory.cs:130dotnet build FullstackTemplate.slnxhas 0 warnings, anddotnet test --solution FullstackTemplate.slnxpassed 1719 of 1719.