From daa991c3d80409b5b686595d90a60ef02bbc4d21 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 21 Jul 2025 13:36:42 +0200 Subject: [PATCH] testutil/environment: don't use regex for string-matching error Signed-off-by: Sebastiaan van Stijn --- testutil/environment/clean.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/testutil/environment/clean.go b/testutil/environment/clean.go index 61ce51ab05..f73be79df1 100644 --- a/testutil/environment/clean.go +++ b/testutil/environment/clean.go @@ -6,7 +6,6 @@ import ( "testing" cerrdefs "github.com/containerd/errdefs" - "github.com/docker/docker/internal/lazyregexp" "github.com/moby/moby/api/types" "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/filters" @@ -64,9 +63,6 @@ func getPausedContainers(ctx context.Context, t testing.TB, client client.Contai return containers } -// FIXME(thaJeztah): can we rewrite this check to not do string-matching, and instead detect error-type? -var alreadyExists = lazyregexp.New(`Error response from daemon: removal of container (\w+) is already in progress`) - func deleteAllContainers(ctx context.Context, t testing.TB, apiclient client.ContainerAPIClient, protectedContainers map[string]struct{}) { t.Helper() containers := getAllContainers(ctx, t, apiclient) @@ -82,7 +78,9 @@ func deleteAllContainers(ctx context.Context, t testing.TB, apiclient client.Con Force: true, RemoveVolumes: true, }) - if err == nil || cerrdefs.IsNotFound(err) || alreadyExists.MatchString(err.Error()) { + + // Ignore if container is already gone, or removal of container is already in progress. + if err == nil || cerrdefs.IsNotFound(err) || strings.Contains(err.Error(), "is already in progress") { continue } assert.Check(t, err, "failed to remove %s", ctr.ID)