fix: pgtest left an anonymous volume behind on every run (#175)
## Problem `go test ./...` leaked one Docker volume per test package. `pgtest.Main` tore its throwaway container down with `docker rm -f` — no `-v`. The `postgres:17-alpine` image declares a `VOLUME` for `/var/lib/postgresql/data`, and an explicit `rm` without `-v` orphans that anonymous volume even though the container was created with `--rm`. Found in passing: a 13-hour-old orphaned pgtest container (AutoRemove, `fsync=off`, one mount) still running from a killed test binary — the same leak's other half. Removed on the dev machine. ## Change - `backend/internal/pgtest/pgtest.go`: `-v` on all three `docker rm -f` teardown sites (`Main`'s defer, and both error paths in `start`). - `AGENTS.md`: cleanup expectation under Commands — `docker compose down -v` for a stack, `docker rm -f -v` for a hand-run container, then check `docker volume ls` and `docker system df`. Explicitly out of bounds: removing the user's `postgres-data` volume, or a blanket `docker system prune` of their images and build cache. ## Verification `docker volume ls` snapshot diffed across a real `./internal/store` run: no new volumes, `docker system df` reports 0 local volumes. Reviewed-on: #175 Co-authored-by: Sulthan Zaki <sultankiki05@gmail.com> Co-committed-by: Sulthan Zaki <sultankiki05@gmail.com>
This commit was merged in pull request #175.
This commit is contained in:
@@ -40,7 +40,9 @@ func Main(m *testing.M) int {
|
||||
fmt.Println("pgtest:", err)
|
||||
return 1
|
||||
}
|
||||
defer exec.Command("docker", "rm", "-f", id).Run()
|
||||
// -v: the postgres image declares a VOLUME, so an explicit rm without it
|
||||
// leaves the anonymous data volume behind on every test run.
|
||||
defer exec.Command("docker", "rm", "-f", "-v", id).Run()
|
||||
|
||||
adminURL = url
|
||||
return m.Run()
|
||||
@@ -85,7 +87,7 @@ func start() (id, url string, err error) {
|
||||
|
||||
port, err := exec.Command("docker", "port", id, "5432/tcp").Output()
|
||||
if err != nil {
|
||||
exec.Command("docker", "rm", "-f", id).Run()
|
||||
exec.Command("docker", "rm", "-f", "-v", id).Run()
|
||||
return "", "", fmt.Errorf("docker port: %w", err)
|
||||
}
|
||||
// "0.0.0.0:32768" (and possibly a second, IPv6 line); the port is all we want.
|
||||
@@ -94,7 +96,7 @@ func start() (id, url string, err error) {
|
||||
first[strings.LastIndex(first, ":")+1:])
|
||||
|
||||
if err := waitReady(url); err != nil {
|
||||
exec.Command("docker", "rm", "-f", id).Run()
|
||||
exec.Command("docker", "rm", "-f", "-v", id).Run()
|
||||
return "", "", err
|
||||
}
|
||||
return id, url, nil
|
||||
|
||||
Reference in New Issue
Block a user