Skip to content

Commit e4f51b7

Browse files
committed
test(worker): pin the clock in the webhook rate limit tests
1 parent 7439767 commit e4f51b7

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

apps/worker/src/webhook-trigger/dispatch-webhook-trigger.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from "vitest";
1+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22
import { eq } from "drizzle-orm";
33
import type { Db } from "../db/client.js";
44
import {
@@ -278,6 +278,19 @@ describe("webhook delivery dispatch", () => {
278278
describe("webhook trigger rate limit", () => {
279279
const perMinute = { max: 1, windowKind: "minute" as const };
280280

281+
// The limit floors the clock into fixed windows, so two dispatches that
282+
// straddle a minute boundary land in different windows and the second one is
283+
// legitimately allowed: on the real clock these tests fail whenever they run
284+
// across :00. Pin the clock mid-window. Only Date is faked, because faking
285+
// the timers as well would stall the awaits these tests are built on.
286+
beforeEach(() => {
287+
vi.useFakeTimers({ toFake: ["Date"], now: new Date("2026-04-01T10:30:30.000Z") });
288+
});
289+
290+
afterEach(() => {
291+
vi.useRealTimers();
292+
});
293+
281294
it("rejects the delivery terminally once the node limit is spent and tallies it", async () => {
282295
const resolveTriggerRateLimit = vi.fn(async () => perMinute);
283296

0 commit comments

Comments
 (0)