-
-
Notifications
You must be signed in to change notification settings - Fork 32k
test: Worker initialization failure test case #31929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
HarshithaKP
wants to merge
9
commits into
nodejs:master
from
HarshithaKP:test_case_worker_init_failed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f69276b
test: Worker initialization failure test case
HarshithaKP 500e991
fixup: remove unwanted file
HarshithaKP 313d520
fixup: address review comments
HarshithaKP 44042ca
fixup: address review comments
HarshithaKP 6a7f905
fixup: cover EMFILE failures generically
HarshithaKP 6a6efb9
fixup: address review comment
HarshithaKP d356e7e
fixup: address review comment
HarshithaKP 520a906
fixup: address review comments
HarshithaKP 1c804df
fixup: address review comment
HarshithaKP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
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 < WORKERCOUNT; ++i) { | ||
const worker = new Worker( | ||
'require(\'worker_threads\').parentPort.postMessage(2 + 2)', | ||
{ eval: true }); | ||
worker.on('message', (result) => { | ||
assert.strictEqual(result, 4); | ||
}); | ||
|
||
// We want to test that if there is an error in a constrained running | ||
// environment, it will be one of `EMFILE` or `ERR_WORKER_INIT_FAILED`. | ||
// `common.mustCall*` cannot be used here as in some environments | ||
// (i.e. single cpu) `ulimit` may not lead to such an error. | ||
|
||
worker.on('error', (e) => { | ||
assert.match(e.message, /EMFILE/); | ||
assert.ok(e.code === 'ERR_WORKER_INIT_FAILED' || e.code === 'EMFILE'); | ||
}); | ||
} | ||
|
||
} else { | ||
// Limit the number of open files, to force workers to fail. | ||
let testCmd = `ulimit -n ${OPENFILES} && `; | ||
testCmd += `${process.execPath} ${__filename} child`; | ||
const cp = child_process.exec(testCmd); | ||
lundibundi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Turn on the child streams for debugging purposes. | ||
let stdout = ''; | ||
cp.stdout.setEncoding('utf8'); | ||
cp.stdout.on('data', (chunk) => { | ||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stdout += chunk; | ||
}); | ||
let stderr = ''; | ||
cp.stderr.setEncoding('utf8'); | ||
cp.stderr.on('data', (chunk) => { | ||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stderr += chunk; | ||
}); | ||
|
||
cp.on('exit', common.mustCall((code, signal) => { | ||
console.log(`child stdout: ${stdout}\n`); | ||
console.log(`child stderr: ${stderr}\n`); | ||
assert.strictEqual(code, 0); | ||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert.strictEqual(signal, null); | ||
})); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.