From ac8491d666b9c1bb5216d20995b9c0c8a3f511dd Mon Sep 17 00:00:00 2001 From: BaaRai <130491490+BaaRai@users.noreply.github.com> Date: Mon, 12 Oct 2026 18:43:41 +0200 Subject: [PATCH] fix: inheritance test teardown closes the manager after the DeleteTask cleanups defer m.Close() ran before the t.Cleanup DeleteTask calls, so they raced a closed database and the late writers they trigger could still touch the temp dir while RemoveAll was already walking it (the CI-only TempDir: directory not empty flake). The manager now closes via a t.Cleanup registered first (runs last, LIFO) and the temp dir is removed with a tolerated failure. --- server/inheritance_api_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/server/inheritance_api_test.go b/server/inheritance_api_test.go index df9fe4f..5c4cc5d 100644 --- a/server/inheritance_api_test.go +++ b/server/inheritance_api_test.go @@ -6,17 +6,32 @@ import ( "fmt" "net/http" "net/http/httptest" + "os" "testing" "github.com/Autumn-27/artex/db" ) func TestInheritedActivityDetailAndRelationDeletion(t *testing.T) { - m, err := NewManager(t.TempDir(), "") + // #78: t.TempDir() cleanup raced with background writers that outlive + // m.Close (TempDir RemoveAll: directory not empty, under CI load). Use a + // manual dir with a tolerated cleanup, and close the manager via t.Cleanup + // registered FIRST so it runs LAST (LIFO): the DeleteTask cleanups below + // then execute while the database is still open instead of racing a closed + // one ("sql: database is closed" teardown noise). + dir, err := os.MkdirTemp("", "inherited-activity-*") if err != nil { + t.Fatal(err) + } + m, err := NewManager(dir, "") + if err != nil { + _ = os.RemoveAll(dir) t.Skipf("postgres unavailable (%v) - skipping", err) } - defer m.Close() + t.Cleanup(func() { + _ = m.Close() + _ = os.RemoveAll(dir) // tolerated: a late background writer may still hold it + }) source, err := m.CreateTaskWithOptions("detail source", "source goal", db.TaskCreateOptions{}) if err != nil {