chore: cleanup

This commit is contained in:
Charlie Lamb
2026-04-24 17:12:24 +01:00
parent 33ecaebb7b
commit f15bbde76a
7 changed files with 120 additions and 55 deletions

View File

@@ -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);
});
});