Skip to content

test: fix make test-all-db TempDir cleanup race#677

Merged
lakhansamani merged 1 commit into
mainfrom
fix/it-tempdir-cleanup-race
Jul 11, 2026
Merged

test: fix make test-all-db TempDir cleanup race#677
lakhansamani merged 1 commit into
mainfrom
fix/it-tempdir-cleanup-race

Conversation

@lakhansamani

Copy link
Copy Markdown
Contributor

Problem

make test-all-db fails locally (macOS) with:

--- FAIL: TestLogout
    testing.go: TempDir RemoveAll cleanup: unlinkat .../TestLogout.../001: directory not empty

The test's assertions pass — only the temp-dir cleanup fails, and only under the full suite (TestLogout passes 5/5 in isolation and is green in CI on Linux).

Root cause

The integration harness puts the SQLite test DB in t.TempDir(), and SQLite runs in WAL mode. The fire-and-forget goroutines from LogEvent/AddSession (started by Login/SignUp/Logout — already documented in the storage-close cleanup comment) can create a -wal/-shm sidecar file exactly as t.TempDir()'s strict RemoveAll tears the dir down → "directory not empty" → Go fails the already-passed test. Pre-existing fragility, not from any recent feature merge.

Fix

Manage the DB's temp dir ourselves instead of t.TempDir(), and remove it best-effort (a few retries, ignore the error) so a benign teardown race can't fail the suite. Registered so removal still runs after the storage Close() cleanup (t.Cleanup is LIFO). Test-only change.

Verification

Full module across all 7 DBs (TEST_DBS=couchbase,postgres,sqlite,mongodb,arangodb,scylladb,dynamodb go test -p 1 ./...) → exit 0, no failures. Storage provider tests across all NoSQL backends also pass (187s), confirming the new org_domains/webauthn_credentials tables round-trip everywhere.

…routines

make test-all-db flaked on macOS: TestLogout (and any integration test)
could fail during teardown with 'TempDir RemoveAll: directory not empty'.
The SQLite test DB lives in the temp dir and uses WAL; the fire-and-forget
LogEvent/AddSession goroutines from Login/SignUp/Logout can create a
-wal/-shm sidecar file exactly as t.TempDir() force-removes the dir,
failing an already-passed test. Manage the dir ourselves and remove it
best-effort (retry, ignore errors) so cleanup-race noise can't fail the
suite. Test-only; green in CI (Linux) already, this fixes the local
full-suite run.
@lakhansamani
lakhansamani merged commit 244d295 into main Jul 11, 2026
4 checks passed
@lakhansamani
lakhansamani deleted the fix/it-tempdir-cleanup-race branch July 11, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant