From 5aceb4d8e4b48bc1656897cfca5a0ea3651917f1 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Wed, 31 Jul 2024 22:36:52 +0100 Subject: [PATCH] fix(registry): wait for Switch registry containers to wait for http response to ensure the container is ready to serve requests, which was causing random test failures. Also remove unnecessary context creation. --- docker_auth_test.go | 5 +---- modules/registry/registry.go | 7 +++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docker_auth_test.go b/docker_auth_test.go index d494d6d12e..b8580a08ea 100644 --- a/docker_auth_test.go +++ b/docker_auth_test.go @@ -286,7 +286,7 @@ func prepareLocalRegistryWithAuth(t *testing.T) string { ContainerFilePath: "/data", }, }, - WaitingFor: wait.ForExposedPort(), + WaitingFor: wait.ForHTTP("/").WithPort("5000/tcp"), } // } @@ -311,9 +311,6 @@ func prepareLocalRegistryWithAuth(t *testing.T) string { removeImageFromLocalCache(t, addr+"/redis:5.0-alpine") }) - _, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - return addr } diff --git a/modules/registry/registry.go b/modules/registry/registry.go index 6cfa3d537b..22aa86be54 100644 --- a/modules/registry/registry.go +++ b/modules/registry/registry.go @@ -220,10 +220,9 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom // convenient for testing "REGISTRY_STORAGE_DELETE_ENABLED": "true", }, - WaitingFor: wait.ForAll( - wait.ForExposedPort(), - wait.ForLog("listening on [::]:5000").WithStartupTimeout(10*time.Second), - ), + WaitingFor: wait.ForHTTP("/"). + WithPort(registryPort). + WithStartupTimeout(10 * time.Second), } genericContainerReq := testcontainers.GenericContainerRequest{