Skip to content

Commit 140f2a9

Browse files
authored
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.
1 parent 31b1ff7 commit 140f2a9

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

agent/agentcontainers/containers_dockercli.go

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
5959
}
6060

6161
dockerPsStderr := strings.TrimSpace(stderrBuf.String())
62+
if len(ids) == 0 {
63+
return codersdk.WorkspaceAgentListContainersResponse{
64+
Warnings: []string{dockerPsStderr},
65+
}, nil
66+
}
6267

6368
// now we can get the detailed information for each container
6469
// Run `docker inspect` on each container ID

agent/agentcontainers/containers_internal_test.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package agentcontainers
22

33
import (
44
"fmt"
5-
"os/exec"
6-
"runtime"
5+
"os"
76
"strconv"
87
"strings"
98
"testing"
@@ -27,15 +26,14 @@ import (
2726
// dockerCLIContainerLister.List method. It starts a container with a known
2827
// label, lists the containers, and verifies that the expected container is
2928
// returned. The container is deleted after the test is complete.
29+
// As this test creates containers, it is skipped by default.
30+
// It can be run manually as follows:
31+
//
32+
// CODER_TEST_USE_DOCKER=1 go test ./agent/agentcontainers -run TestDockerCLIContainerLister
3033
func TestDockerCLIContainerLister(t *testing.T) {
3134
t.Parallel()
32-
if runtime.GOOS != "linux" {
33-
t.Skip("creating containers on non-linux runners is slow and flaky")
34-
}
35-
36-
// Conditionally skip if Docker is not available.
37-
if _, err := exec.LookPath("docker"); err != nil {
38-
t.Skip("docker not found in PATH")
35+
if ctud, ok := os.LookupEnv("CODER_TEST_USE_DOCKER"); !ok || ctud != "1" {
36+
t.Skip("Set CODER_TEST_USE_DOCKER=1 to run this test")
3937
}
4038

4139
pool, err := dockertest.NewPool("")

0 commit comments

Comments
 (0)