Skip to content

Commit

Permalink
add error handling for worker threads
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityvi committed Jul 21, 2023
1 parent 3cf114f commit 8eb4bd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/runner/concurrency/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class Concurrency extends EventEmitter {
if (this.isSafariEnvPresent) {
extraArgs.push('--serial');
}
let childProcess = this.createChildProcess(environment, args, extraArgs, index);
const childProcess = this.createChildProcess(environment, args, extraArgs, index);

return this.runChildProcess(childProcess, environment + ' environment', availColors, 'envs');
}));
Expand Down Expand Up @@ -296,7 +296,12 @@ class Concurrency extends EventEmitter {
});


return Promise.all(workerPool.tasks);
return new Promise((resolve, reject) => {
Promise.allSettled(workerPool.tasks)
.then(values => {
values.some(({status}) => status === 'rejected') ? reject() : resolve();
});
});
}


Expand Down
6 changes: 6 additions & 0 deletions lib/runner/concurrency/worker-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class WorkerTask extends EventEmitter {
port2.unref();

return this.piscina.run({argv: this.argv, port1}, {transferList: [port1]})
.catch(err => err)
.then(failures => {
if (this.settings.disable_output_boxes){
// eslint-disable-next-line no-console
Expand All @@ -102,6 +103,11 @@ class WorkerTask extends EventEmitter {
// eslint-disable-next-line no-console
console.log(boxen(this.task_output.join('\n'), {title: `────────────────── ${failures ? symbols.fail : symbols.ok} ${this.task_label}`, padding: 1, borderColor: 'cyan'}));
}

//throw error to mark exit-code of the process
if (failures) {
throw new Error();
}
});
}
}
Expand Down

0 comments on commit 8eb4bd4

Please sign in to comment.