test: use Set for promises
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 31 May 2023 12:46:03 +0000 (14:46 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 31 May 2023 12:46:03 +0000 (14:46 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
tests/pools/abstract/abstract-pool.test.js
tests/pools/cluster/fixed.test.js
tests/pools/thread/fixed.test.js

index 108fb32a03f1c10d629a9a4bf33da46e4169987d..1c0146252593604c5b74269c908a86674aae2f79 100644 (file)
@@ -327,10 +327,10 @@ describe('Abstract pool test suite', () => {
       numberOfWorkers,
       './tests/worker-files/cluster/testWorker.js'
     )
-    const promises = []
+    const promises = new Set()
     const maxMultiplier = 2
     for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) {
-      promises.push(pool.execute())
+      promises.add(pool.execute())
     }
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
@@ -372,10 +372,10 @@ describe('Abstract pool test suite', () => {
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
     )
-    const promises = []
+    const promises = new Set()
     const maxMultiplier = 2
     for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) {
-      promises.push(pool.execute())
+      promises.add(pool.execute())
     }
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
@@ -422,7 +422,7 @@ describe('Abstract pool test suite', () => {
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
     )
-    const promises = []
+    const promises = new Set()
     let poolFull = 0
     pool.emitter.on(PoolEvents.full, () => ++poolFull)
     for (let i = 0; i < numberOfWorkers * 2; i++) {
@@ -440,7 +440,7 @@ describe('Abstract pool test suite', () => {
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
     )
-    const promises = []
+    const promises = new Set()
     let poolBusy = 0
     pool.emitter.on(PoolEvents.busy, () => ++poolBusy)
     for (let i = 0; i < numberOfWorkers * 2; i++) {
index dfd765574a7437ef9ac128c9a35d7185cb7ab10b..ac5d1fda6943a67651ea521e924cfcf8283a20c3 100644 (file)
@@ -113,7 +113,6 @@ describe('Fixed cluster pool test suite', () => {
       expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier)
       expect(workerNode.tasksQueue.size).toBe(0)
     }
-    promises.clear()
   })
 
   it('Verify that is possible to have a worker that return undefined', async () => {
index 0c3ba276f3b4e40c4d2d40e2a5484efd679cb094..ef368968922282de2d5090f4d68242946c46e481 100644 (file)
@@ -113,7 +113,6 @@ describe('Fixed thread pool test suite', () => {
       expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier)
       expect(workerNode.tasksQueue.size).toBe(0)
     }
-    promises.clear()
   })
 
   it('Verify that is possible to have a worker that return undefined', async () => {