fix(benchmark): remove timeouting in benchmark.js
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 31 Mar 2024 20:12:00 +0000 (22:12 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 31 Mar 2024 20:12:00 +0000 (22:12 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
benchmarks/benchmarks-utils.mjs

index 0cd3a172456d85efc733281cccc68cb323b44747..0971e683413c4fc420586a6d4423e5be27f5a0a2 100644 (file)
@@ -83,34 +83,30 @@ export const runPoolifierBenchmarkBenchmarkJs = async (
   { taskExecutions, workerData }
 ) => {
   return await new Promise((resolve, reject) => {
-    let pool = buildPoolifierPool(workerType, poolType, poolSize)
+    const pool = buildPoolifierPool(workerType, poolType, poolSize)
     try {
       const suite = new Benchmark.Suite(name, {
         onComplete: () => {
-          const destroyTimeout = setTimeout(() => {
-            console.error('Pool destroy timeout reached (30s)')
+          if (pool.started && !pool.destroying) {
+            pool.destroy().then(resolve).catch(reject)
+          } else {
             resolve()
-            pool = undefined
-          }, 30000)
-          pool
-            .destroy()
-            .then(resolve)
-            .catch(reject)
-            .finally(() => {
-              clearTimeout(destroyTimeout)
-            })
-            .catch(() => {})
+          }
         },
         onCycle: event => {
           console.info(event.target.toString())
         },
         onError: event => {
-          pool
-            .destroy()
-            .then(() => {
-              return reject(event.target.error)
-            })
-            .catch(() => {})
+          if (pool.started && !pool.destroying) {
+            pool
+              .destroy()
+              .then(() => {
+                return reject(event.target.error)
+              })
+              .catch(() => {})
+          } else {
+            reject(event.target.error)
+          }
         }
       })
       for (const workerChoiceStrategy of Object.values(