Skip to content

Commit

Permalink
Further reduce log flooding when parallel execution terminates early
Browse files Browse the repository at this point in the history
  • Loading branch information
sgravrock committed Jul 5, 2024
1 parent b71b3be commit 75fd5bb
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions lib/parallel_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ class ParallelWorker {
// spec files.
for (const errorType of ['uncaughtException', 'unhandledRejection']) {
options.process.on(errorType, error => {
if (this.clusterWorker_.isConnected()) {
this.clusterWorker_.send({
type: errorType,
error: serializeError(error)
});
} else {
// Don't try to report errors after disconnect. If we do, it'll cause
// another unhandled exception. The resulting error-and-reporting loop
// can keep the runner from finishing.
console.error(`${errorType} in Jasmine worker process after disconnect:`, error);
const sent = sendIfConnected(this.clusterWorker_, {
type: errorType,
error: serializeError(error)
});

if (!sent) {
console.error(`${errorType} in Jasmine worker process after disconnect:`,
error);
console.error('This error cannot be reported properly because it ' +
'happened after the worker process was disconnected.'
);
Expand Down Expand Up @@ -150,11 +148,7 @@ function forwardingReporter(clusterWorker) {

for (const eventName of eventNames) {
reporter[eventName] = function (payload) {
if (!clusterWorker.isConnected()) {
return;
}

clusterWorker.send({
sendIfConnected(clusterWorker, {
type: 'reporterEvent',
eventName,
payload: {
Expand All @@ -170,4 +164,22 @@ function forwardingReporter(clusterWorker) {
return reporter;
}

function sendIfConnected(clusterWorker, msg) {
if (clusterWorker.isConnected()) {
try {
clusterWorker.send(msg);
return true;
} catch (e) {
// EPIPE may be thrown if the worker receives a disconnect between
// the calls to isConnected() and send() above.
if (e.code !== 'EPIPE') {
throw e;
}
}
}

return false;
}


module.exports = ParallelWorker;

0 comments on commit 75fd5bb

Please sign in to comment.