From 2bc15a6f8adebcab4d785085836251c7ace3bce3 Mon Sep 17 00:00:00 2001 From: Marcus Pousette Date: Sun, 21 Jul 2024 17:04:42 +0200 Subject: [PATCH] test: add concurrency test --- packages/utils/indexer/tests/src/tests.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/utils/indexer/tests/src/tests.ts b/packages/utils/indexer/tests/src/tests.ts index 3381555b9..c11eb6052 100644 --- a/packages/utils/indexer/tests/src/tests.ts +++ b/packages/utils/indexer/tests/src/tests.ts @@ -3368,6 +3368,28 @@ export const tests = ( } }); + describe("concurrency", () => { + it("can handle concurrent counts", async () => { + let results: number[] = []; + let promises: Promise[] = []; + await setupDefault(); + for (let i = 0; i < 100; i++) { + promises.push( + (async () => { + results.push(await store.count(new CountRequest())); + })(), + ); + } + await Promise.all(promises); + expect(results).to.have.length(100); + try { + expect(results.every((x) => x === 4)).to.be.true; + } catch (error) { + console.log(results); + throw error; + } + }); + }); describe("drop", () => { it("store", async () => { let { directory, indices, store } = await setupDefault();