Skip to content

User/ggarzia/cache container images - #41353

Draft
ggarzia-MSFT wants to merge 2 commits into
masterfrom
user/ggarzia/cache-container-images
Draft

User/ggarzia/cache container images#41353
ggarzia-MSFT wants to merge 2 commits into
masterfrom
user/ggarzia/cache-container-images

Conversation

@ggarzia-MSFT

@ggarzia-MSFT ggarzia-MSFT commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Adds a TestImageRegistry to the wslc E2E tests that tracks which test images are already
loaded 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

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Test-only change; no product code is touched.

Previously every test class independently ran EnsureImageIsLoaded in setup and
EnsureImageIsDeleted in 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.

TestImageRegistry is a per-process singleton that seeds itself once per session from a
live image list query, then answers EnsureLoaded from memory. Shared-image deletes were
removed 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, NoteCommand is hooked into the three RunWslc primitives and observes every
wslc 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 the
cache 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-qualified
references). 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 EnsureImageIsLoaded and
EnsureImageIsDeleted helpers are deleted. Delete deliberately queries image list
directly 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:

Arm Runs Mean Spread
master 428.00 / 430.96 / 429.72 429.56 s 3.0 s
this change 385.55 / 384.40 / 388.04 386.00 s 3.6 s

43.56 s faster (10.1%), 475/475 passing on all six runs. Ranges are separated by a 40 s
gap with no overlap.

ggarzia-MSFT and others added 2 commits August 13, 2026 16:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 13, 2026 23:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 serve EnsureLoaded from memory, plus a Delete helper 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 TestImageRegistry APIs and removed the legacy EnsureImageIsLoaded/EnsureImageIsDeleted helpers.

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});
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.

2 participants