User/ggarzia/cache container images - #41353
Draft
ggarzia-MSFT wants to merge 2 commits into
Draft
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes WSLC Windows E2E test execution by introducing a per-process TestImageRegistry that caches which base test images are already loaded per session, avoiding repeated image list + image load work across many test classes. It integrates registry invalidation by observing WSLC commands executed via the existing executor helpers.
Changes:
- Added
TestImageRegistry(singleton) to seed per-session image inventory once and serveEnsureLoadedfrom memory, plus aDeletehelper that queries live inventory to remove images safely. - Hooked command observation (
NoteCommand) into WSLC executor entry points so cache state is invalidated when removal-like commands are issued. - Updated WSLC E2E tests to use
TestImageRegistryAPIs and removed the legacyEnsureImageIsLoaded/EnsureImageIsDeletedhelpers.
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/windows/wslc/e2e/WSLCExecutor.cpp | Hooks TestImageRegistry::NoteCommand() into WSLC execution paths. |
| test/windows/wslc/e2e/WSLCE2EWarningTests.cpp | Switches setup to TestImageRegistry::EnsureLoaded; removes shared-image cleanup. |
| test/windows/wslc/e2e/WSLCE2EVolumeRemoveTests.cpp | Uses registry-based image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EVolumePruneTests.cpp | Uses registry-based image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2ETlsRegistryTests.cpp | Uses registry-based image load for named sessions. |
| test/windows/wslc/e2e/WSLCE2ERegistryTests.cpp | Uses registry-based image load for test image prerequisites. |
| test/windows/wslc/e2e/WSLCE2EPushPullTests.cpp | Uses registry-based image load for push/pull prerequisites. |
| test/windows/wslc/e2e/WSLCE2ENetworkTests.cpp | Uses registry-based image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2ENetworkPruneTests.cpp | Uses registry-based image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EInspectTests.cpp | Uses registry-based image load and registry Delete for test-created images. |
| test/windows/wslc/e2e/WSLCE2EImageTagTests.cpp | Uses registry EnsureLoaded / Delete and reduces cleanup deletions to avoid thrash. |
| test/windows/wslc/e2e/WSLCE2EImageSaveTests.cpp | Uses registry image load/delete for save/load flows and cleanup. |
| test/windows/wslc/e2e/WSLCE2EImagePruneTests.cpp | Uses registry image load/delete in prune scenarios and cleanup. |
| test/windows/wslc/e2e/WSLCE2EImageListTests.cpp | Uses registry image load and removes shared-image cleanup. |
| test/windows/wslc/e2e/WSLCE2EImageInspectTests.cpp | Uses registry image load and registry Delete for built image cleanup. |
| test/windows/wslc/e2e/WSLCE2EImageImportTests.cpp | Uses registry image load/delete for import prerequisites and cleanup. |
| test/windows/wslc/e2e/WSLCE2EImageDeleteTests.cpp | Uses registry image load/delete for delete command test setup/cleanup. |
| test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp | Uses registry image load for build prerequisites; removes shared-image cleanup. |
| test/windows/wslc/e2e/WSLCE2EHelpers.h | Removes declarations of legacy image load/delete helpers. |
| test/windows/wslc/e2e/WSLCE2EHelpers.cpp | Removes implementations of legacy image load/delete helpers; adds registry include. |
| test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp | Uses registry image load for session-targeted tests. |
| test/windows/wslc/e2e/WSLCE2EContainerStopTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerStatsTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerRunTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerRemoveTests.cpp | Uses registry image load and registry Delete for test-created images. |
| test/windows/wslc/e2e/WSLCE2EContainerPruneTests.cpp | Uses registry image load in class setup. |
| test/windows/wslc/e2e/WSLCE2EContainerLogsTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerListTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerKillTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerInspectTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerExportTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerExecTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp | Uses registry image load; uses registry Delete for test-created images. |
| test/windows/wslc/e2e/WSLCE2EContainerCpTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/WSLCE2EContainerAttachTests.cpp | Uses registry image load; removes shared-image deletion from cleanup. |
| test/windows/wslc/e2e/TestImageRegistry.h | Introduces the registry API and cached state structures. |
| test/windows/wslc/e2e/TestImageRegistry.cpp | Implements seeding, load/delete behavior, and command-based invalidation logic. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+129
to
+140
| void TestImageRegistry::EnsureSeeded(const std::wstring& sessionName) | ||
| { | ||
| { | ||
| auto lock = m_lock.lock_shared(); | ||
| if (m_seededSessions.contains(sessionName)) | ||
| { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| auto result = RunWslc(FormatCommand(sessionName, L"image list --format json")); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); |
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.
Summary of the Pull Request
Adds a
TestImageRegistryto the wslc E2E tests that tracks which test images are alreadyloaded in a session, so repeated setup across test classes stops reloading the same image
tarballs. Measured 43.6 s (10.1%) faster across the 475 affected tests.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Test-only change; no product code is touched.
Previously every test class independently ran
EnsureImageIsLoadedin setup andEnsureImageIsDeletedin cleanup. Because classes share a small set of base images(debian, alpine, hello-world, python), each cleanup deleted an image the next class
immediately reloaded, costing ~1 s per reload.
TestImageRegistryis a per-process singleton that seeds itself once per session from alive
image listquery, then answersEnsureLoadedfrom memory. Shared-image deletes wereremoved from class cleanups; images that a test genuinely needs gone are still deleted
explicitly.
Keeping a cache honest is the hard part, so rather than trusting call sites to report
mutations,
NoteCommandis hooked into the threeRunWslcprimitives and observes everywslc invocation. Only removal verbs matter —
image remove/delete/rm,image prune,and
system session terminate— because commands that add an image can at worst leave thecache pessimistic, which costs one extra query rather than producing a wrong answer.
Invalidation is per-image where the command names its targets, and session-wide only when
the affected set can't be known (
image prune, session teardown, digest or port-qualifiedreferences). This distinction matters: an earlier revision invalidated session-wide on every
removal, which destroyed the seed and gave back 13.5 s of the win.
All image handling now lives on the registry; the free
EnsureImageIsLoadedandEnsureImageIsDeletedhelpers are deleted.Deletedeliberately queriesimage listdirectly instead of consulting the cache, since built and imported images are created
outside the registry and a cached negative would silently leak them.
Validation Steps Performed
Full 475-test cacheable selection (27 classes), x64 Debug, 3 runs per arm against an
identical deployment:
43.56 s faster (10.1%), 475/475 passing on all six runs. Ranges are separated by a 40 s
gap with no overlap.