ssh docker test: detach cleanup ctx from t.Context · Entire

ssh docker test: detach cleanup ctx from t.Context

8adeada→main·

Soph·2mo ago·1 file·+6 added/-2

t.Context is canceled the moment the test returns, so the docker rm / docker image rm subprocesses registered via t.Cleanup were never able to run, leaking the test image (~35MB per run).

Sessions

74fd06e0aef8View transcript

[?
can you fix the linting errorClaude Code·1 step](/content/gh/entireio/git-sync/session/ff0a7d3f-e73b-48cc-a5d1-49b930a82fdf#timeline-74fd06e0aef8/index.html)

Changes

1

65 unmodified lines

66
67
68
69
69
70
71
72
73
74
5 unmodified lines

80
81
82
81
83
84
85
86
87
88

65 unmodified lines

imageTag := fmt.Sprintf("git-sync-ssh-e2e:%d", rand.New(rand.NewSource(time.Now().UnixNano())).Int63())
    runCommand(t, imageCtx, "docker", "build", "-t", imageTag, ".")

t.Cleanup(func() {
    if err := runCommandBestEffort(t.Context(), root, "docker", "image", "rm", "-f", imageTag); err != nil {
        ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
        defer cancel()
        if err := runCommandBestEffort(ctx, root, "docker", "image", "rm", "-f", imageTag); err != nil {
            t.Logf("cleanup docker image: %v", err)
        }
    }
})
5 unmodified lines

imageTag,
    ))
t.Cleanup(func() {
    if err := runCommandBestEffort(t.Context(), root, "docker", "rm", "-f", containerID); err != nil {
        ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
        defer cancel()
        if err := runCommandBestEffort(ctx, root, "docker", "rm", "-f", containerID); err != nil {
            t.Logf("cleanup docker container: %v", err)
        }
    }
})

Minternal/syncer/ssh_docker_test.go+6/-2