Skip to content

Commit 1db6071

Browse files
authored
test(queue): cover async onStop cleanup (#4638)
1 parent 3ea5c10 commit 1db6071

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/execution/incremental/Queue.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,9 @@ export class Queue<T> {
121121
}
122122
} catch (error) {
123123
const stopped = this._stop(error);
124-
/* c8 ignore start */
125-
// TODO: add coverage
126124
if (isPromise(stopped)) {
127125
stopped.catch(() => undefined);
128126
}
129-
/* c8 ignore stop */
130127
}
131128
}
132129

src/execution/incremental/__tests__/Queue-test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,40 @@ describe('Queue', () => {
396396
await expectPromise(sub.next()).toRejectWith('Oops');
397397
});
398398

399+
it('waits for async onStop cleanup after sync executor error', async () => {
400+
const { promise: cleanup, resolve: resolveCleanup } =
401+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
402+
promiseWithResolvers<void>();
403+
let cleanupCalled = false;
404+
const sub = new Queue(({ onStop }) => {
405+
onStop(() => {
406+
cleanupCalled = true;
407+
return cleanup;
408+
});
409+
throw new Error('Oops');
410+
}).subscribe();
411+
412+
const nextPromise = sub.next();
413+
let nextSettled = false;
414+
nextPromise.then(
415+
() => {
416+
nextSettled = true;
417+
},
418+
() => {
419+
nextSettled = true;
420+
},
421+
);
422+
423+
await resolveOnNextTick();
424+
expect(cleanupCalled).to.equal(true);
425+
expect(nextSettled).to.equal(false);
426+
427+
resolveCleanup();
428+
429+
await expectPromise(nextPromise).toRejectWith('Oops');
430+
expect(nextSettled).to.equal(true);
431+
});
432+
399433
it('delivers queued items before rejecting on async executor error', async () => {
400434
const sub = new Queue(async ({ push }) => {
401435
push(1);

0 commit comments

Comments
 (0)