From 2d539c2094c67f85db9dde41c9606df3d86fda09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Kamy=C5=9Fev?= Date: Thu, 7 Mar 2024 23:01:06 +0700 Subject: [PATCH] Test case for possible bug, issue #426 (#427) Add tests cases for possible bug --- .../concurrency/__tests__/concurrency.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/core/src/concurrency/__tests__/concurrency.test.ts b/packages/core/src/concurrency/__tests__/concurrency.test.ts index 01a8e00af..ae1291d90 100644 --- a/packages/core/src/concurrency/__tests__/concurrency.test.ts +++ b/packages/core/src/concurrency/__tests__/concurrency.test.ts @@ -86,4 +86,32 @@ describe('concurrency', async () => { ] `); }); + + test('TAKE_LATEST and 2 simultaneous requests lead to correct status, issue #426', async () => { + const q = createQuery({ + async handler(id: string) { + const defer = createDefer(); + + onAbort(() => defer.reject()); + + await setTimeout(1); + defer.resolve(id); + + return defer.promise; + }, + }); + + concurrency(q, { strategy: 'TAKE_LATEST' }); + + const scope = fork(); + + allSettled(q.start, { scope, params: '1' }); + allSettled(q.start, { scope, params: '2' }); + + expect(scope.getState(q.$pending)).toBeTruthy(); + + await allSettled(scope); + + expect(scope.getState(q.$pending)).toBeFalsy(); + }); });