From 5a048cbea27c5b3577125ca9940533d9d854e39c Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 17 May 2026 12:22:06 -0400 Subject: [PATCH] fix(ci): serialize integration test packages (-p 1) to stop TRUNCATE deadlocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First CI integration run proved the act_runner pattern works (service discovery, migrate, exactly-one guard all functioned) but ~150 tests failed with `dbtest.ResetDB truncate: deadlock detected (40P01)` plus cascading FK/dup-key symptoms. Root cause: `go test ./...` runs package binaries concurrently (default -p = NumCPU); every integration package TRUNCATEs the single shared minstrel_test DB, so concurrent truncates deadlock and half-seeded fixtures violate FKs. The documented local invocation is `go test -p 1 ./...` for exactly this reason. Serialize package execution in both the CI step and `make test-integration`. Genuine (non-concurrency) failures will remain after this — never caught before because integration tests never ran in CI. Triaged next. Co-Authored-By: Claude Opus 4.7 (1M context) --- .forgejo/workflows/test-go.yml | 7 +++++-- Makefile | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.forgejo/workflows/test-go.yml b/.forgejo/workflows/test-go.yml index 3906148b..60b0ce60 100644 --- a/.forgejo/workflows/test-go.yml +++ b/.forgejo/workflows/test-go.yml @@ -104,6 +104,9 @@ jobs: for i in $(seq 1 60); do (echo > "/dev/tcp/${PG_IP}/5432") 2>/dev/null && break; sleep 2; done # Apply embedded migrations to the fresh test DB, then run the - # full suite (no -short → integration tests execute). + # full suite (no -short → integration tests execute). -p 1: + # every integration package TRUNCATEs the one shared test DB; + # concurrent package binaries → TRUNCATE deadlocks. Serialize + # package execution (the documented local invocation too). MINSTREL_DATABASE_URL="$MINSTREL_TEST_DATABASE_URL" go run ./cmd/minstrel migrate - go test -race ./... + go test -p 1 -race ./... diff --git a/Makefile b/Makefile index 9799d2ff..fa1e2e04 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,9 @@ test-short: test-integration: docker compose up -d postgres -docker compose exec -T postgres createdb -U minstrel minstrel_test - MINSTREL_TEST_DATABASE_URL=postgres://minstrel:minstrel@localhost:5432/minstrel_test?sslmode=disable go test -race ./... + # -p 1: integration packages share one test DB and each TRUNCATEs it; + # concurrent package binaries deadlock on TRUNCATE. Serialize packages. + MINSTREL_TEST_DATABASE_URL=postgres://minstrel:minstrel@localhost:5432/minstrel_test?sslmode=disable go test -p 1 -race ./... lint: golangci-lint run ./...