test(forge): cover cancellation with shared list readers

This commit is contained in:
Yichen Jiang committed 2026-10-26 21:25:53 +08:00
1 parent db36fafc3a
commit d82b72b3d7
2 files changed
+17 -2

No files matched your search

@@ -108,7 +108,6 @@ class Reader {
constructor(readonly allowed: (id: SessionId) => boolean, private readonly signal: AbortSignal) {
signal.addEventListener('abort', this.abort, { once: true })
if (signal.aborted) this.end()
}
push(state: ForgeChangeRequestListState): void {
@@ -207,7 +206,6 @@ class Run {
}
private bind(id: SessionId, urls: readonly string[]): void {
if (this.stopped) return
const next = new Set(urls)
const previous = this.urlsOf.get(id) ?? new Set<string>()
this.urlsOf.set(id, next)
@@ -350,4 +350,21 @@ describe('ChangeRequestStates', () => {
expect(await reader(f.hub).next()).toEqual({ type: 'baseline', states: [] })
})
it('keeps other readers live when a reader aborts between frames', async () => {
const f = fixture([{ id: S1, urls: [url(7)] }])
const aborter = new AbortController()
const first = f.hub.stream(() => true, aborter.signal)[Symbol.asyncIterator]()
const second = reader(f.hub)
await first.next()
await second.next()
aborter.abort()
f.poll(7)
expect((await first.next()).done).toBe(true)
expect(await second.next()).toEqual({ type: 'changed', states: [state(7)] })
expect([...f.watchers.keys()]).toEqual([7])
await second.close()
expect([...f.watchers.keys()]).toEqual([])
})
})