diff --git a/tests/integration/count-synchronization.test.ts b/tests/integration/count-synchronization.test.ts index 8e6d19f8..6923ab6d 100644 --- a/tests/integration/count-synchronization.test.ts +++ b/tests/integration/count-synchronization.test.ts @@ -34,6 +34,14 @@ describe('Count Synchronization (Bug Fix v4.1.2)', () => { }) afterEach(async () => { + // Close the brain first so its writer-lock heartbeat + flush timers stop + // before the directory is removed — otherwise they race teardown and bleed + // state into the next test. + try { + await brain?.close() + } catch { + // Best-effort teardown. + } // Clean up test directory try { await fs.rm(testPath, { recursive: true, force: true }) diff --git a/tests/integration/get-relations-fix.test.ts b/tests/integration/get-relations-fix.test.ts index 71efad6f..451e34a0 100644 --- a/tests/integration/get-relations-fix.test.ts +++ b/tests/integration/get-relations-fix.test.ts @@ -33,6 +33,14 @@ describe('related() call patterns', () => { }) afterEach(async () => { + // Close the brain first so its writer-lock heartbeat + flush timers stop + // before the directory is removed — otherwise they race teardown and bleed + // state into the next test. + try { + await brain?.close() + } catch { + // Best-effort teardown. + } // Clean up test directory try { await fs.rm(testPath, { recursive: true, force: true })