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 <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • 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.