feat: 支持多实例客户端异常限流

This commit is contained in:
que01 committed 2026-10-23 12:57:06 +08:00
1 parent 4cd3749806
commit 2fe108d66a
18 files changed
+432 -90

No files matched your search

@@ -0,0 +1,24 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { createClientErrorThrottleStore } from "../src/modules/admin/client-error-throttle.factory.js";
import { PostgresClientErrorThrottleStore } from "../src/modules/admin/client-error-throttle.postgres.store.js";
import { MemoryClientErrorThrottleStore } from "../src/modules/admin/client-error-throttle.store.js";
const prisma = {} as never;
test("默认使用进程内存储", () => {
const store = createClientErrorThrottleStore(prisma, "memory");
assert.ok(store instanceof MemoryClientErrorThrottleStore);
});
test("多实例可切换为 Postgres 共享存储", () => {
const store = createClientErrorThrottleStore(prisma, "postgres");
assert.ok(store instanceof PostgresClientErrorThrottleStore);
});
test("未知存储模式在启动时快速失败", () => {
assert.throws(
() => createClientErrorThrottleStore(prisma, "redis"),
/Unsupported CLIENT_ERROR_THROTTLE_STORE/,
);
});