Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache result of Docker OS to speed up XUnit test discovery #6216

Open
wants to merge 1 commit into
base: nightly
Choose a base branch
from

Conversation

lbussell
Copy link
Contributor

@lbussell lbussell commented Feb 7, 2025

I got frustrated with slow Test Discovery and used PerfView on a run of our unit tests to see why it took so long. DockerOS was being accessed many times during test discovery because we have the custom LinuxImageTheory attribute. Each time it was accessed, it took two seconds to call docker.exe, even though the result never changes during a single test run.

Wrapping it in a Lazy<> speeds up test discovery by a factor of ~60.

Before - 27.64 seconds

Starting test discovery, please wait...
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.5+1caef2f33e (64-bit .NET 9.0.1)
[xUnit.net 00:00:00.70]   Discovering: Microsoft.DotNet.Docker.Tests
[xUnit.net 00:00:28.34]   Discovered:  Microsoft.DotNet.Docker.Tests

After - 0.44 seconds

Starting test discovery, please wait...
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.5+1caef2f33e (64-bit .NET 9.0.1)
[xUnit.net 00:00:00.66]   Discovering: Microsoft.DotNet.Docker.Tests
[xUnit.net 00:00:01.10]   Discovered:  Microsoft.DotNet.Docker.Tests

@lbussell lbussell requested a review from a team as a code owner February 7, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant