chore: cleanup
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { startPollingLoop } from "@/queue/initWorkers.js";
|
||||
import {
|
||||
getAbortControllerCountForTesting,
|
||||
startPollingLoop,
|
||||
} from "@/queue/initWorkers.js";
|
||||
|
||||
const originalSetTimeout = globalThis.setTimeout;
|
||||
|
||||
@@ -86,4 +89,35 @@ describe("startPollingLoop", () => {
|
||||
expect(shouldPollCalls).toBe(1);
|
||||
expect(sendCalls).toBe(1);
|
||||
});
|
||||
|
||||
test("does not leak abort controllers when the SQS client is recreated", async () => {
|
||||
let sendCalls = 0;
|
||||
let recreateCalls = 0;
|
||||
const makeClient = (abortAfterRecreate: boolean) =>
|
||||
({
|
||||
send: async () => {
|
||||
sendCalls++;
|
||||
if (abortAfterRecreate) {
|
||||
throw makeAbortError();
|
||||
}
|
||||
return { Messages: [] };
|
||||
},
|
||||
}) as never;
|
||||
|
||||
await startPollingLoop({
|
||||
db: {} as never,
|
||||
queueUrl: "https://sqs.eu-west-1.amazonaws.com/123/track.fifo",
|
||||
isFifo: true,
|
||||
getSqsClientFn: () => makeClient(false),
|
||||
recreateSqsClientFn: () => {
|
||||
recreateCalls++;
|
||||
return makeClient(true);
|
||||
},
|
||||
shouldPoll: () => true,
|
||||
});
|
||||
|
||||
expect(recreateCalls).toBe(1);
|
||||
expect(sendCalls).toBeGreaterThan(9);
|
||||
expect(getAbortControllerCountForTesting()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user