test: cleanup AsyncLock test
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 3 Aug 2024 13:20:48 +0000 (15:20 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 3 Aug 2024 13:20:48 +0000 (15:20 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/utils/AsyncLock.ts
tests/utils/AsyncLock.test.ts

index eef006dbbe96cb93b9a505383924b33d9be14014..95a90c21715499a31ea34be2dc56b677fde16936 100644 (file)
@@ -52,7 +52,7 @@ export class AsyncLock {
       return
     }
     await new Promise<void>(resolve => {
-      asyncLock.resolveQueue.dequeue()
+      asyncLock.resolveQueue.dequeue()?.()
       resolve()
     })
   }
index dbec498a5773de4e90914d1a4aab40a167ee1b83..162d357e28a05047a4cb036526f76a029214f3fd 100644 (file)
@@ -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)