Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🚥 test: Hold Group Cache Reads Until Concurrent Callers Arrive (#16059)
lia-by-librechat[bot]02efb1d6b5e6
diff --git a/packages/data-schemas/src/methods/userGroup.spec.ts b/packages/data-schemas/src/methods/userGroup.spec.tsindex 46ba4cdc7d..7a33ac633c 100644--- a/packages/data-schemas/src/methods/userGroup.spec.ts+++ b/packages/data-schemas/src/methods/userGroup.spec.ts@@ -484,11 +484,14 @@ describe('userGroup methods', () => {});describe('getUserPrincipals caching', () => {- function createFakeCache() {+ function createFakeCache({ onRead }: { onRead?: () => Promise<void> } = {}) {const store = new Map<string, unknown>();return {store,- get: jest.fn(async (key: string) => store.get(key)),+ get: jest.fn(async (key: string) => {+ await onRead?.();+ return store.get(key);+ }),set: jest.fn(async (key: string, value: unknown) => {store.set(key, value);}),@@ -497,6 +500,29 @@ describe('userGroup methods', () => {};}+ /**+ * Holds each cache read until `callers` of them are inside the miss window together, so a+ * test about deduplicating concurrent builds actually gets concurrent builds. Delaying+ * every read by a fixed few milliseconds instead leaves the overlap up to the scheduler:+ * under load the first build can finish before a later caller reads, and that caller then+ * takes the miss path on its own, which is correct behaviour but not what such a test is+ * asserting. Reads after the barrier opens pass straight through, so a caller that reads+ * again mid-build (after taking the lock, say) cannot deadlock.+ */+ function arrivalBarrier(callers: number) {+ let arrived = 0;+ let open!: () => void;+ const allArrived = new Promise<void>((resolve) => {+ open = resolve;+ });+ return async () => {+ if (++arrived >= callers) {+ open();+ }+ await allArrived;+ };+ }+function createCachedMethods(cache: ReturnType<typeof createFakeCache>) {return createUserGroupMethods(mongoose, { getCache: jest.fn(() => cache) });}@@ -758,14 +784,8 @@ describe('userGroup methods', () => {it('deduplicates concurrent cache builds for the same member key', async () => {const user = await createTestUser({ idOnTheSource: 'dedup-ext-1' });- const cache = {- get: jest.fn(async () => {- await new Promise((resolve) => setTimeout(resolve, 10));- return undefined;- }),- set: jest.fn(async () => undefined),- };- const cachedMethods = createUserGroupMethods(mongoose, { getCache: jest.fn(() => cache) });+ const cache = createFakeCache({ onRead: arrivalBarrier(3) });+ const cachedMethods = createCachedMethods(cache);const params = {userId: user._id.toString(),role: SystemRoles.USER,@@ -787,11 +807,7 @@ describe('userGroup methods', () => {it('shares one lock and DB build across concurrent same-process callers', async () => {const user = await createTestUser({ idOnTheSource: 'lock-ext-1' });const cache = {- get: jest.fn(async () => {- await new Promise((resolve) => setTimeout(resolve, 10));- return undefined;- }),- set: jest.fn(async () => undefined),+ ...createFakeCache({ onRead: arrivalBarrier(3) }),acquireLock: jest.fn(async () => 'lock-token'),releaseLock: jest.fn(async () => undefined),lockWaitMs: 5000,