Skip to content

Simplify e2e build-test image cleanup with per-test RAII ownership - #41094

Merged
ggarzia-MSFT merged 3 commits into
masterfrom
user/ggarzia/buildTestImageCleanup
Jul 17, 2026
Merged

Simplify e2e build-test image cleanup with per-test RAII ownership#41094
ggarzia-MSFT merged 3 commits into
masterfrom
user/ggarzia/buildTestImageCleanup

Conversation

@ggarzia-MSFT

Copy link
Copy Markdown
Contributor

This pull request refactors the image cleanup logic in the WSLCE2EImageBuildTests end-to-end test suite to be more robust and maintainable. It introduces a new helper function for bulk image deletion by repository prefix, replaces per-method sweeping with targeted per-test cleanup, and removes the old manual deletion code. The changes improve test reliability, especially in the presence of test failures or crashes.

Test cleanup improvements:

  • Added a new helper function DeleteImagesWithRepositoryPrefix that deletes all images whose repository names start with a given prefix, making bulk cleanup more reliable and less error-prone. [1] [2]
  • Updated class-level setup and cleanup in WSLCE2EImageBuildTests to use the new prefix-based image deletion helper, ensuring any leftover images from previous runs are removed.
  • Removed per-method sweeping (DeleteAllBuiltImages) in favor of using an RAII-style DeleteImageOnExit guard for each test, which ensures only images created by a test are cleaned up, even if the test fails. [1] [2] [3] [4] [5] [6] [7] [8]
  • Removed the now-unnecessary DeleteAllBuiltImages method and its invocations, simplifying the codebase.
  • Updated test documentation and comments to clarify the new cleanup strategy and its rationale.Replace the hand-maintained DeleteAllBuiltImages() static list (run in both TEST_METHOD_SETUP and TEST_METHOD_CLEANUP, sweeping every built image twice per test and flooding the log with VERIFY lines) with:
  • A per-test DeleteImageOnExit() RAII guard so each test owns and cleans up exactly the image(s) it builds. It is best-effort and non-throwing (no VERIFY) since it may run during stack unwinding after a failure.
  • A single class-level DeleteImagesWithRepositoryPrefix() prune in ClassSetup and ClassCleanup as the authoritative safety net for images left behind by a crashed run.

This removes the per-method sweeps, the static image list, and the excessive per-field VERIFY logging that dominated test output.

Summary of the Pull Request

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

Validation Steps Performed

Replace the hand-maintained DeleteAllBuiltImages() static list (run in both
TEST_METHOD_SETUP and TEST_METHOD_CLEANUP, sweeping every built image twice per
test and flooding the log with VERIFY lines) with:

- A per-test DeleteImageOnExit() RAII guard so each test owns and cleans up
  exactly the image(s) it builds. It is best-effort and non-throwing (no
  VERIFY) since it may run during stack unwinding after a failure.
- A single class-level DeleteImagesWithRepositoryPrefix() prune in ClassSetup
  and ClassCleanup as the authoritative safety net for images left behind by a
  crashed run.

This removes the per-method sweeps, the static image list, and the excessive
per-field VERIFY logging that dominated test output.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 16, 2026 18:15
@ggarzia-MSFT
ggarzia-MSFT requested review from a team as code owners July 16, 2026 18:15

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

Refactors the WSLC image-build end-to-end tests’ cleanup strategy to reduce per-test log noise and improve resilience by moving from a hardcoded “sweep everything” list to per-test RAII cleanup plus a class-level safety-net prune.

Changes:

  • Replaced per-method DeleteAllBuiltImages() sweeps with per-test DeleteImageOnExit() RAII guards for images built in each test.
  • Added DeleteImagesWithRepositoryPrefix() helper and used it in class setup/cleanup as the crash-recovery safety net.
  • Removed the hand-maintained DeleteAllBuiltImages() list and associated setup/cleanup hooks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp Switches to per-test RAII image deletion and class-level prefix-based pruning.
test/windows/wslc/e2e/WSLCE2EHelpers.h Declares the new prefix-based image deletion helper.
test/windows/wslc/e2e/WSLCE2EHelpers.cpp Implements prefix-based bulk image deletion via image list --format json.

Comment thread test/windows/wslc/e2e/WSLCE2EHelpers.cpp
Added comments to clarify image deletion logic in WSLCE2EHelpers.cpp.
Copilot AI review requested due to automatic review settings July 16, 2026 20:01

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp
Copilot AI review requested due to automatic review settings July 16, 2026 20:51

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread test/windows/wslc/e2e/WSLCE2EHelpers.cpp
@ggarzia-MSFT
ggarzia-MSFT merged commit f8a67e9 into master Jul 17, 2026
12 checks passed
@ggarzia-MSFT
ggarzia-MSFT deleted the user/ggarzia/buildTestImageCleanup branch July 17, 2026 00:06
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.

4 participants