test(hygiene): close every brain the unit suite creates
Each file opened one or more Brainy instances (beforeEach, or a small per-test helper like migration-gate-family-scoped's module-level seed()) and never closed them. migration-gate-family-scoped.test.ts now tracks every brain seed() hands back in a describe-scoped array drained by afterEach, since the helper itself lives outside the describe block.
This commit is contained in:
parent
d6e7453f1f
commit
de79d6b5a4
16 changed files with 83 additions and 15 deletions
|
|
@ -18,7 +18,7 @@
|
|||
* the production feature-detection reads it.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { Brainy, NounType, MigrationInProgressError } from '../../src/index.js'
|
||||
import { GraphAdjacencyIndex } from '../../src/graph/graphAdjacencyIndex.js'
|
||||
|
||||
|
|
@ -39,6 +39,12 @@ describe('Migration LOCK (#18) — coordinated 7.x→8.0 auto-upgrade', () => {
|
|||
await brain.init()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
// The "close() is not gated" test already closes `brain` itself as its
|
||||
// own assertion — closing an already-closed brain is a safe no-op here.
|
||||
await brain.close().catch(() => {})
|
||||
})
|
||||
|
||||
it('does not gate operations when no provider is migrating (fast path)', async () => {
|
||||
const id = await brain.add({ data: 'hello', type: NounType.Concept })
|
||||
expect(id).toBeTruthy()
|
||||
|
|
@ -130,6 +136,9 @@ describe('Migration LOCK (#18) — coordinated 7.x→8.0 auto-upgrade', () => {
|
|||
expect(e).toBeInstanceOf(MigrationInProgressError)
|
||||
expect(e.retryable).toBe(true)
|
||||
expect(typeof e.elapsedMs).toBe('number')
|
||||
} finally {
|
||||
// close() is proven not-gated by the test below — safe even mid-migration.
|
||||
await shortBrain.close()
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
Reference in a new issue