test(hygiene): close every brain the find suite creates
tests/integration/find-*.test.ts and tests/unit/brainy/find*.test.ts each opened one or more Brainy instances (via beforeAll/beforeEach) and never closed them — the leaked instance's cadence timer stays armed for the rest of the single-forked vitest run and keeps narrating into every later file. find-unified-integration.test.ts was a real bug, not just a missing hook: its afterAll called a no-op TestCleanup().cleanup() (nothing was ever registered with it) and then discarded the brain reference with `brain = null` — the brain was never actually closed.
This commit is contained in:
parent
4c81d7d4c3
commit
4c344782a7
8 changed files with 37 additions and 8 deletions
|
|
@ -19,7 +19,7 @@
|
|||
* index-served (a body field, or a bucketed timestamp), exactly the owing rows
|
||||
* are read and the rest are still served from the index.
|
||||
*/
|
||||
import { describe, it, expect, beforeAll, vi } from 'vitest'
|
||||
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
|
||||
import { Brainy } from '../../src/brainy'
|
||||
import { NounType } from '../../src/types/graphTypes'
|
||||
import { generateTestVector } from '../helpers/test-factory'
|
||||
|
|
@ -59,6 +59,10 @@ describe('find/get({ fields }) — projection', () => {
|
|||
await brain.flush()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
/** Count canonical record reads for one call. */
|
||||
const countingReads = async <R>(body: () => Promise<R>): Promise<{ out: R; reads: number }> => {
|
||||
const spy = vi.spyOn(brain as any, 'batchGet')
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
* it). Now the anchor is fetched with its vector, and an anchor without one
|
||||
* refuses by name instead of failing inside the index.
|
||||
*/
|
||||
import { describe, it, expect, beforeAll } from 'vitest'
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
||||
import { Brainy } from '../../src/brainy'
|
||||
import { NounType } from '../../src/types/graphTypes'
|
||||
import { v5 } from '../../src/universal/uuid'
|
||||
|
|
@ -28,6 +28,10 @@ describe('find({ near }) uses the anchor vector', () => {
|
|||
await brain.add({ id: 'far', data: 'far row', type: NounType.Thing, vector: generateTestVector() })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
it('returns the anchor\'s neighbours by its own vector', async () => {
|
||||
const results = await brain.find({ near: { id: 'anchor' }, limit: 3 })
|
||||
expect(results.length).toBeGreaterThan(0)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
* the covering is ASSERTED from the leg's own output rather than assumed. This
|
||||
* pin is about ordering, and it says nothing about recall.
|
||||
*/
|
||||
import { describe, it, expect, beforeAll } from 'vitest'
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
||||
import { Brainy } from '../../src/brainy'
|
||||
import { NounType, VerbType } from '../../src/types/graphTypes'
|
||||
import { resolveEntityId } from '../../src/utils/idNormalization'
|
||||
|
|
@ -107,6 +107,10 @@ describe('find(): orderBy is the order on every path', () => {
|
|||
}
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
it('the fixture: the hybrid candidate set covers the whole filter universe', async () => {
|
||||
const universe: string[] = await (brain as any).filterIdsBelted({ lane: 'alpha' })
|
||||
expect(universe).toHaveLength(ROWS)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
* against the adjacency before it is believed, so a not-serving graph refuses
|
||||
* loudly instead of answering `[]` as truth.
|
||||
*/
|
||||
import { describe, it, expect, beforeAll, vi } from 'vitest'
|
||||
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
|
||||
import { Brainy } from '../../src/brainy'
|
||||
import { NounType, VerbType } from '../../src/types/graphTypes'
|
||||
import { generateTestVector } from '../helpers/test-factory'
|
||||
|
|
@ -56,6 +56,10 @@ describe('find(): the optional planner door', () => {
|
|||
}
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
/** Install a planner door for one call, then remove it. */
|
||||
const withDoor = async <T>(
|
||||
door: (...a: any[]) => Promise<any>,
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ describe('Unified Find() Integration Tests', () => {
|
|||
|
||||
afterAll(async () => {
|
||||
await cleanup.cleanup()
|
||||
await brain.close()
|
||||
brain = null as any
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
* soft-delete semantic: `field !== value` MUST include entities that have no
|
||||
* such field at all.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { Brainy } from '../../../src/brainy'
|
||||
import { NounType } from '../../../src/types/graphTypes'
|
||||
|
||||
|
|
@ -26,6 +26,10 @@ describe('find() complement operators (ne / exists:false / missing:true)', () =>
|
|||
ids.noField2 = await brain.add({ data: 'n2', type: NounType.Thing, metadata: { other: 2 } })
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
it('ne returns everything except the matching value — INCLUDING entities without the field', async () => {
|
||||
const rows = await brain.find({ where: { status: { ne: 'active' } }, limit: 100 })
|
||||
const got = new Set(rows.map((r) => r.id))
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
* returns an id whose record matches NEITHER the type nor the where filter) and
|
||||
* assert the phantom is dropped while the genuine matches survive.
|
||||
*/
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { Brainy } from '../../../src/brainy'
|
||||
import { NounType } from '../../../src/types/graphTypes'
|
||||
|
||||
|
|
@ -48,6 +48,10 @@ describe('find() index-integrity guard (phantom row class)', () => {
|
|||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
it('healthy index: the discriminant query returns only the staff Person', async () => {
|
||||
const rows = await brain.find({ type: NounType.Person, where: { entityType: 'staff' }, limit: 100 })
|
||||
expect(rows.map((r) => r.id)).toEqual([staffId])
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
||||
import { Brainy } from '../../../src/brainy'
|
||||
import { createAddParams } from '../../helpers/test-factory'
|
||||
import { NounType } from '../../../src/types/graphTypes'
|
||||
|
|
@ -12,7 +12,11 @@ describe('Brainy.find()', () => {
|
|||
})
|
||||
await brain.init()
|
||||
})
|
||||
|
||||
|
||||
afterEach(async () => {
|
||||
await brain.close()
|
||||
})
|
||||
|
||||
describe('success paths', () => {
|
||||
it('should find entities by text query', async () => {
|
||||
// Arrange
|
||||
|
|
|
|||
Reference in a new issue