Repository navigation
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
Changes from 1 commit
f69276b
500e991
313d520
44042ca
6a7f905
6a6efb9
d356e7e
520a906
1c804df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Cover the scenario fixed through #31621 Unfortunately there is no easy way to test this, in a cross-platform manner. So the approach is: - open a child process with ulimit restriction on file descriptors - in the child process, start few workers - more than the fd limit - make sure some workers fail, with the expected error type. - skip the test in windows, as there is no ulimit there.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| '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 (process.argv[2] === 'child') { | ||
| const {Worker} = require('worker_threads'); | ||
| for (let i = 0; i < 256; ++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.strictEqual(e.code, 'ERR_WORKER_INIT_FAILED'); | ||
| }) | ||
| } | ||
|
|
||
| } else { | ||
|
|
||
| if (common.isWindows) { | ||
| common.skip('ulimit does not work on Windows.'); | ||
| } | ||
|
|
||
| // limit the number of open files, to force workers to fail | ||
| let testCmd = 'ulimit -n 128 && '; | ||
|
|
||
| testCmd += `${process.argv[0]} ${process.argv[1]} child`; | ||
| const cp = child_process.exec(testCmd); | ||
|
|
||
| // turn on the child streams for debugging purpose | ||
| cp.stderr.on('data', (d) => { | ||
| console.log(d.toString()); | ||
| }) | ||
| cp.stdout.on('data', (d) => { | ||
| console.log(d.toString()); | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||
| '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 (process.argv[2] === 'child') { | ||||
| const { Worker } = require('worker_threads'); | ||||
| for (let i = 0; i < 256; ++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.strictEqual(e.code, 'ERR_WORKER_INIT_FAILED'); | ||||
| }); | ||||
| } | ||||
|
addaleax marked this conversation as resolved.
Resolved
|
||||
|
|
||||
| } else { | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lundibundi, thanks. Removed the extra line. |
||||
| if (common.isWindows) { | ||||
| common.skip('ulimit does not work on Windows.'); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe instead of skipping the test, just skip the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this is an error in the test and therefore after it is resolved it will no longer be runnable on windows.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Trott , with respect to Windows - is there any merit in running a test that doesn't make any assertion ? |
||||
| } | ||||
|
lundibundi marked this conversation as resolved.
Resolved
|
||||
|
|
||||
| // Limit the number of open files, to force workers to fail | ||||
| let testCmd = 'ulimit -n 128 && '; | ||||
|
lundibundi marked this conversation as resolved.
Resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason not to go with something much smaller than
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Trott, When I ran a simple node.js code, it created 30+ file descriptors. If I reduce the fd count to 8, it fails at arbitrary point without / before reaching worker creation. |
||||
|
|
||||
| testCmd += `${process.argv[0]} ${process.argv[1]} child`; | ||||
|
lundibundi marked this conversation as resolved.
Resolved
|
||||
| const cp = child_process.exec(testCmd); | ||||
|
lundibundi marked this conversation as resolved.
Resolved
|
||||
|
|
||||
| // Turn on the child streams for debugging purpose | ||||
|
lundibundi marked this conversation as resolved.
Resolved
|
||||
| cp.stderr.on('data', (d) => { | ||||
| console.log(d.toString()); | ||||
| }); | ||||
| cp.stdout.on('data', (d) => { | ||||
| console.log(d.toString()); | ||||
| }); | ||||
|
lundibundi marked this conversation as resolved.
Resolved
|
||||
| } | ||||
|
lundibundi marked this conversation as resolved.
Resolved
|
||||
Uh oh!
There was an error while loading. Please reload this page.