From: Jérôme Benoit Date: Sat, 3 Aug 2024 13:20:48 +0000 (+0200) Subject: test: cleanup AsyncLock test X-Git-Tag: ocpp-server@v1.5.2~133 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=213958d630327ba513982a7f18642b09ec5a03c8;p=e-mobility-charging-stations-simulator.git test: cleanup AsyncLock test Signed-off-by: Jérôme Benoit --- 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)