Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: address review comments
  • Loading branch information
HarshithaKP committed Feb 25, 2020
commit 313d520f63cca47f2d5172d228f7125e85ff4cd1
46 changes: 33 additions & 13 deletions test/parallel/test-worker-init-failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,58 @@ const child_process = require('child_process');
// Test that workers fail with meaningful error message
// when their initialization fails.

if (common.isWindows) {
common.skip('ulimit does not work on Windows.');
}

// A reasonably low fd count. An empty node process
// creates around 30 fds for its internal purposes,
// so making it too low will crash the process early,
// making it too high will cause too much resource use.
const OPENFILES = 128;

// Double the open files - so that some workers fail for sure.
const WORKERCOUNT = 256;

if (process.argv[2] === 'child') {
const { Worker } = require('worker_threads');
for (let i = 0; i < 256; ++i) {
for (let i = 0; i < WORKERCOUNT; ++i) {
const worker = new Worker(
'require(\'worker_threads\').parentPort.postMessage(2 + 2)',
{ eval: true });
worker.on('message', (result) => {
assert.strictEqual(result, 4);
});
worker.on('error', (e) => {
assert(e.message.match(/Worker initialization failure: EMFILE/));
assert.match(e.message, /Worker initialization failure: EMFILE/);
assert.strictEqual(e.code, 'ERR_WORKER_INIT_FAILED');
});
}
Comment thread
addaleax marked this conversation as resolved.

} else {

if (common.isWindows) {
common.skip('ulimit does not work on Windows.');
}

// Limit the number of open files, to force workers to fail
Comment thread
lundibundi marked this conversation as resolved.
Outdated
let testCmd = 'ulimit -n 128 && ';
let testCmd = `ulimit -n ${OPENFILES} && `;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lundibundi, thanks. Removed the extra line.

testCmd += `${process.argv[0]} ${process.argv[1]} child`;
testCmd += `${process.execPath} ${__filename} child`;
const cp = child_process.exec(testCmd);
Comment thread
lundibundi marked this conversation as resolved.

let stdout = '';
let stderr = '';

cp.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
Comment thread
addaleax marked this conversation as resolved.
assert.strictEqual(signal, null);
if (stdout !== '')
console.log(`child stdout: ${stdout}`);
if (stderr !== '')
console.log(`child stderr: ${stderr}`);
}));

// Turn on the child streams for debugging purpose
Comment thread
lundibundi marked this conversation as resolved.
Outdated
cp.stderr.on('data', (d) => {
console.log(d.toString());
cp.stderr.on('data', (chunk) => {
stdout += chunk;
});
cp.stdout.on('data', (d) => {
console.log(d.toString());
cp.stdout.on('data', (chunk) => {
stderr += chunk;
});
}
Comment thread
lundibundi marked this conversation as resolved.