test(native-chat): cancel the journal import test's tick before teardown (#24071)

The test re-arms a setImmediate tick while the copy runs and stopped it with a
flag. A tick already queued when the import resolved still ran, and when the
afterEach teardown closed the database first it threw journal_closed as an
unhandled error, failing a CI shard with every test green. Clear the queued
tick instead.
This commit is contained in:
Brennan Benson
2026-09-30 23:36:43 -07:00
committed by GitHub
parent 2a83c9536f
commit a37e5026fc
@@ -331,23 +331,21 @@ describe('importing a per-chat journal', () => {
})
)
const between: number[] = []
let copying = true
const tick = (): void => {
// What a live chat's append would commit under, between two copy batches.
between.push(synchronous())
if (copying) {
setImmediate(tick)
}
pending = setImmediate(tick)
}
setImmediate(tick)
let pending = setImmediate(tick)
await importPerSessionJournal({
database,
identity: IDENTITY,
legacyDirectory: legacyDir(),
batchRows: 1
})
copying = false
// A flag would still let the queued tick read the database after teardown closes it.
clearImmediate(pending)
// 2 is FULL, 1 is NORMAL.
expect(commits.slice(0, rows.length)).toEqual(rows.map(() => 1))