-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
test: spawn new processes in vm-cached-data #6280
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
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 |
|---|---|---|
|
|
@@ -2,19 +2,36 @@ | |
| require('../common'); | ||
| const assert = require('assert'); | ||
| const vm = require('vm'); | ||
| const spawnSync = require('child_process').spawnSync; | ||
| const Buffer = require('buffer').Buffer; | ||
|
|
||
| function getSource(tag) { | ||
| return `(function ${tag}() { return \'${tag}\'; })`; | ||
| } | ||
|
|
||
| function produce(source) { | ||
| const script = new vm.Script(source, { | ||
| produceCachedData: true | ||
| }); | ||
| assert(!script.cachedDataProduced || script.cachedData instanceof Buffer); | ||
| function produce(source, count) { | ||
| if (!count) | ||
| count = 1; | ||
|
|
||
| const out = spawnSync(process.execPath, [ '-p', ` | ||
| var assert = require('assert'); | ||
| var vm = require('vm'); | ||
|
|
||
| for (var i = 0; i < ${count}; i++) { | ||
| var script = new vm.Script(process.argv[1], { | ||
| produceCachedData: true | ||
| }); | ||
|
|
||
| assert(!script.cachedDataProduced || script.cachedData instanceof Buffer); | ||
|
|
||
| if (script.cachedDataProduced) | ||
| script.cachedData.toString('base64'); | ||
|
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. The return value isn't used. I think you intended to
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. It is JS, the last statement will be printed when using
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. Hm, very subtle. I guess it's not wrong but it's not very obviously correct, either. I'd use
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. Ack, I agree. |
||
| } | ||
| `, source]); | ||
|
|
||
| assert.equal(out.status, 0, out.stderr + ''); | ||
|
|
||
| return script.cachedData; | ||
| return new Buffer(out.stdout.toString(), 'base64'); | ||
|
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.
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. Ack. |
||
| } | ||
|
|
||
| function testProduceConsume() { | ||
|
|
@@ -34,9 +51,7 @@ testProduceConsume(); | |
| function testProduceMultiple() { | ||
| const source = getSource('original'); | ||
|
|
||
| produce(source); | ||
| produce(source); | ||
| produce(source); | ||
| produce(source, 3); | ||
| } | ||
| testProduceMultiple(); | ||
|
|
||
|
|
||
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.
Just for my understanding,
process.argv[1] === undefinedhere, right?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.
It is not, see
sourceon line 32.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.
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.
Bet you didn't know about this 😉
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.
Oh, I missed the third argument. Never mind.