Skip to content

Commit ec99b32

Browse files
fix: bound container cleanup termination with 30s timeout
CodeRabbit nitpick: c.Terminate(context.Background()) could block indefinitely; use a timeout-bound context instead. Co-authored-by: German Arutyunov <gaarutyunov@users.noreply.github.com>
1 parent 147f067 commit ec99b32

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

internal/testutil/containers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package testutil
55
import (
66
"context"
77
"testing"
8+
"time"
89

910
"github.com/testcontainers/testcontainers-go"
1011
)
@@ -21,7 +22,9 @@ func MustStartContainer(ctx context.Context, t *testing.T, req testcontainers.Co
2122
t.Fatalf("start container %q: %v", req.Image, err)
2223
}
2324
t.Cleanup(func() {
24-
if err := c.Terminate(context.Background()); err != nil {
25+
termCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
26+
defer cancel()
27+
if err := c.Terminate(termCtx); err != nil {
2528
t.Logf("terminate container %q: %v", req.Image, err)
2629
}
2730
})

0 commit comments

Comments
 (0)