From 213958d630327ba513982a7f18642b09ec5a03c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 3 Aug 2024 15:20:48 +0200 Subject: [PATCH] test: cleanup AsyncLock test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/AsyncLock.ts | 2 +- tests/utils/AsyncLock.test.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/utils/AsyncLock.ts b/src/utils/AsyncLock.ts index eef006db..95a90c21 100644 --- a/src/utils/AsyncLock.ts +++ b/src/utils/AsyncLock.ts @@ -52,7 +52,7 @@ export class AsyncLock { return } await new Promise(resolve => { - asyncLock.resolveQueue.dequeue() + asyncLock.resolveQueue.dequeue()?.() resolve() }) } diff --git a/tests/utils/AsyncLock.test.ts b/tests/utils/AsyncLock.test.ts index dbec498a..162d357e 100644 --- a/tests/utils/AsyncLock.test.ts +++ b/tests/utils/AsyncLock.test.ts @@ -5,9 +5,9 @@ import { expect } from 'expect' import { AsyncLock, AsyncLockType } from '../../src/utils/AsyncLock.js' await describe('AsyncLock test suite', async () => { - await it('Verify runExclusive()', () => { + await it('Verify runExclusive() on sync fn', () => { const runs = 10 - let executed: number[] = [] + const executed: number[] = [] let count = 0 const fn = () => { executed.push(++count) @@ -21,8 +21,12 @@ await describe('AsyncLock test suite', async () => { // eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable .catch(console.error) } - executed = [] - count = 0 + }) + + await it('Verify runExclusive() on async fn', () => { + const runs = 10 + const executed: number[] = [] + let count = 0 const asyncFn = async () => { await new Promise(resolve => { setTimeout(resolve, 100) -- 2.34.1