From 140f2a9013d56de9a541d200ea086201a3d36e04 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Mon, 10 Feb 2025 12:12:32 +0000 Subject: [PATCH] chore(agent/agentcontainers): skip TestDockerCLIContainerLister by default (#16502) Addresses a test flake seen here: https://github.com/coder/coder/actions/runs/13239819615/job/36952521742 Also addresses the case where we would try to run `docker inspect` with no container IDs, which is a silly thing to do. --- agent/agentcontainers/containers_dockercli.go | 5 +++++ .../agentcontainers/containers_internal_test.go | 16 +++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/agent/agentcontainers/containers_dockercli.go b/agent/agentcontainers/containers_dockercli.go index e7364125b8..3842735116 100644 --- a/agent/agentcontainers/containers_dockercli.go +++ b/agent/agentcontainers/containers_dockercli.go @@ -59,6 +59,11 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi } dockerPsStderr := strings.TrimSpace(stderrBuf.String()) + if len(ids) == 0 { + return codersdk.WorkspaceAgentListContainersResponse{ + Warnings: []string{dockerPsStderr}, + }, nil + } // now we can get the detailed information for each container // Run `docker inspect` on each container ID diff --git a/agent/agentcontainers/containers_internal_test.go b/agent/agentcontainers/containers_internal_test.go index b9f34261dd..e15deae54c 100644 --- a/agent/agentcontainers/containers_internal_test.go +++ b/agent/agentcontainers/containers_internal_test.go @@ -2,8 +2,7 @@ package agentcontainers import ( "fmt" - "os/exec" - "runtime" + "os" "strconv" "strings" "testing" @@ -27,15 +26,14 @@ import ( // dockerCLIContainerLister.List method. It starts a container with a known // label, lists the containers, and verifies that the expected container is // returned. The container is deleted after the test is complete. +// As this test creates containers, it is skipped by default. +// It can be run manually as follows: +// +// CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -run TestDockerCLIContainerLister func TestDockerCLIContainerLister(t *testing.T) { t.Parallel() - if runtime.GOOS != "linux" { - t.Skip("creating containers on non-linux runners is slow and flaky") - } - - // Conditionally skip if Docker is not available. - if _, err := exec.LookPath("docker"); err != nil { - t.Skip("docker not found in PATH") + if ctud, ok := os.LookupEnv("CODER_TEST_USE_DOCKER"); !ok || ctud != "1" { + t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test") } pool, err := dockertest.NewPool("")