From 0d6756030d91b0d055af9629865e97217e270eba Mon Sep 17 00:00:00 2001 From: Yuhang Wei Date: Thu, 5 Feb 2026 14:32:44 +0800 Subject: [PATCH] test: fix flaky TestImageConvert/soci by pruning stale cache and ensuring image The `TestImageConvert/soci` sub-test was failing intermittently due to an inconsistent content store state. The SOCI converter detected existing zTOC indices (stale cache from previous runs) and skipped generation, but subsequently failed because the referenced source image blobs were missing. The failure manifested as: `soci: layer ... -> ztoc ... (already exists)` followed by `content digest ... not found`. This commit adds a `Setup` step to the soci sub-test that: 1. Executes `system prune --force` to clear stale zTOC artifacts and dangling blobs. 2. Explicitly pulls the source image to ensure all necessary content is present before conversion. Signed-off-by: Yuhang Wei --- cmd/nerdctl/image/image_convert_linux_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/nerdctl/image/image_convert_linux_test.go b/cmd/nerdctl/image/image_convert_linux_test.go index a13fc08d595..d10ec5b40a5 100644 --- a/cmd/nerdctl/image/image_convert_linux_test.go +++ b/cmd/nerdctl/image/image_convert_linux_test.go @@ -97,6 +97,12 @@ func TestImageConvert(t *testing.T) { nerdtest.Soci, nerdtest.SociVersion("0.10.0"), ), + Setup: func(data test.Data, helpers test.Helpers) { + // Clean up any existing SOCI indices to avoid stale ztoc data + helpers.Anyhow("rmi", "-f", testutil.CommonImage) + helpers.Anyhow("system", "prune", "--force") + helpers.Ensure("pull", "--quiet", "--all-platforms", testutil.CommonImage) + }, Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier("converted-image")) }, @@ -115,6 +121,12 @@ func TestImageConvert(t *testing.T) { nerdtest.Soci, nerdtest.SociVersion("0.10.0"), ), + Setup: func(data test.Data, helpers test.Helpers) { + // Clean up any existing SOCI indices to avoid stale ztoc data + helpers.Anyhow("rmi", "-f", testutil.CommonImage) + helpers.Anyhow("system", "prune", "--force") + helpers.Ensure("pull", "--quiet", "--all-platforms", testutil.CommonImage) + }, Cleanup: func(data test.Data, helpers test.Helpers) { helpers.Anyhow("rmi", "-f", data.Identifier("converted-image")) }, @@ -130,7 +142,6 @@ func TestImageConvert(t *testing.T) { } testCase.Run(t) - } func TestImageConvertNydusVerify(t *testing.T) {