Skip to content

Commit

Permalink
worker: improve coverage
Browse files Browse the repository at this point in the history
This improves the worker coverage by using `internal/assert` instead
of relying on `assert` in case a faulty worker message type is
received.

PR-URL: #27230
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
BridgeAR authored and ZYSzys committed Apr 17, 2019
1 parent 5450e48 commit d070f5d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const {

const publicWorker = require('worker_threads');

const assert = require('internal/assert');

patchProcessObject();
setupInspectorHooks();
setupDebugEnv();
Expand Down Expand Up @@ -122,18 +124,17 @@ port.on('message', (message) => {
process.argv[1] = filename; // script filename
require('module').runMain();
}
return;
} else if (message.type === STDIO_PAYLOAD) {
const { stream, chunk, encoding } = message;
process[stream].push(chunk, encoding);
return;
} else if (message.type === STDIO_WANTS_MORE_DATA) {
} else {
assert(
message.type === STDIO_WANTS_MORE_DATA,
`Unknown worker message type ${message.type}`
);
const { stream } = message;
process[stream][kStdioWantsMoreDataCallback]();
return;
}

require('assert').fail(`Unknown worker message type ${message.type}`);
});

// Overwrite fatalException
Expand Down

0 comments on commit d070f5d

Please sign in to comment.