-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
tests: reduce runtime #20688
tests: reduce runtime #20688
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,17 @@ if (process.argv[2] === 'async') { | |
fn(); | ||
throw new Error(); | ||
} | ||
(async function() { await fn(); })(); | ||
// While the above should error, just in case it doesn't the script shouldn't | ||
// fork itself indefinitely so return early. | ||
return; | ||
return (async function() { await fn(); })(); | ||
} | ||
|
||
const assert = require('assert'); | ||
const { spawnSync } = require('child_process'); | ||
|
||
const ret = spawnSync(process.execPath, [__filename, 'async']); | ||
const ret = spawnSync( | ||
process.execPath, | ||
['--stack_size=50', __filename, 'async'] | ||
); | ||
assert.strictEqual(ret.status, 0); | ||
assert.ok(!/async.*hook/i.test(ret.stderr.toString('utf8', 0, 1024))); | ||
const stderr = ret.stderr.toString('utf8', 0, 2048); | ||
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. Why the increase in 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 checked the actual output and it was cut off relatively early without printing a lot of information. By increasing that limit it actually makes sure we really test for the right values. |
||
assert.ok(!/async.*hook/i.test(stderr)); | ||
assert.ok(stderr.includes('UnhandledPromiseRejectionWarning: Error'), stderr); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,24 @@ if (process.env.NODE_PENDING_DEPRECATION) | |
common.skip('test does not work when NODE_PENDING_DEPRECATION is set'); | ||
|
||
function test(main, callSite, expected) { | ||
const { stderr } = child_process.spawnSync(process.execPath, ['-p', ` | ||
process.mainModule = { filename: ${JSON.stringify(main)} }; | ||
const child = child_process.spawn(process.execPath, [ | ||
'-p', | ||
`process.mainModule = { filename: ${JSON.stringify(main)} };` + | ||
"vm.runInNewContext('new Buffer(10)', { Buffer }, {" + | ||
` filename: ${JSON.stringify(callSite)}` + | ||
'});' | ||
], { encoding: 'utf8' }); | ||
|
||
vm.runInNewContext('new Buffer(10)', { Buffer }, { | ||
filename: ${JSON.stringify(callSite)} | ||
});`], { encoding: 'utf8' }); | ||
if (expected) | ||
assert(stderr.includes('[DEP0005] DeprecationWarning'), stderr); | ||
else | ||
assert.strictEqual(stderr.trim(), ''); | ||
let stderr = ''; | ||
child.stderr.on('data', (value) => { | ||
stderr += value.toString(); | ||
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. Please always use |
||
}); | ||
child.on('exit', () => { | ||
if (expected) | ||
assert(stderr.includes('[DEP0005] DeprecationWarning')); | ||
else | ||
assert.strictEqual(stderr.trim(), ''); | ||
}); | ||
} | ||
|
||
test('/a/node_modules/b.js', '/a/node_modules/x.js', false); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
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. Same here. Can we move the child process code to a fixture? 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 moving these things to a fixture is the wrong thing to do. We have a lot of fixtures and there is no benefit this in a fixture as far as I see it. It is much easier to handle this test if everything is together. The fixtures folder is full with things of which probably no one has an idea about what is really in there. |
||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const stdoutData = 'foo'; | ||
const stderrData = 'bar'; | ||
const expectedStdout = `${stdoutData}\n`; | ||
const expectedStderr = `${stderrData}\n`; | ||
|
||
if (process.argv[2] === 'child') { | ||
// The following console calls are part of the test. | ||
console.log(stdoutData); | ||
console.error(stderrData); | ||
} else { | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const expectedStdout = `${stdoutData}\n`; | ||
const expectedStderr = `${stderrData}\n`; | ||
function run(options, callback) { | ||
const cmd = `"${process.execPath}" "${__filename}" child`; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren’t we never supposed to change the stack size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this lowers the size that V8 assumes to have, it should be fine. This is also the only main reason for this test to run ~3x faster. I personally think it is fine to use here because it would still work even if the flag would be a no-op. @hashseed @bmeurer are you fine with me using this in this case?