test: spawn new processes in vm-cached-data
V8 may start caching scripts from the first run soon. Preventively execute scripts in another process to ensure no test failures due to an update in the future. See: #6258 PR-URL: https://github.com/nodejs/node/pull/6280 Reviewed-By: Jochen Eisinger <jochen@chromium.org> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
5f0fcd6245
commit
e1cf634a0b
@ -2,19 +2,38 @@
|
|||||||
require('../common');
|
require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
|
const spawnSync = require('child_process').spawnSync;
|
||||||
const Buffer = require('buffer').Buffer;
|
const Buffer = require('buffer').Buffer;
|
||||||
|
|
||||||
function getSource(tag) {
|
function getSource(tag) {
|
||||||
return `(function ${tag}() { return \'${tag}\'; })`;
|
return `(function ${tag}() { return \'${tag}\'; })`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function produce(source) {
|
function produce(source, count) {
|
||||||
const script = new vm.Script(source, {
|
if (!count)
|
||||||
|
count = 1;
|
||||||
|
|
||||||
|
const out = spawnSync(process.execPath, [ '-e', `
|
||||||
|
var assert = require('assert');
|
||||||
|
var vm = require('vm');
|
||||||
|
|
||||||
|
let data;
|
||||||
|
for (var i = 0; i < ${count}; i++) {
|
||||||
|
var script = new vm.Script(process.argv[1], {
|
||||||
produceCachedData: true
|
produceCachedData: true
|
||||||
});
|
});
|
||||||
|
|
||||||
assert(!script.cachedDataProduced || script.cachedData instanceof Buffer);
|
assert(!script.cachedDataProduced || script.cachedData instanceof Buffer);
|
||||||
|
|
||||||
return script.cachedData;
|
if (script.cachedDataProduced)
|
||||||
|
data = script.cachedData.toString('base64');
|
||||||
|
}
|
||||||
|
console.log(data);
|
||||||
|
`, source]);
|
||||||
|
|
||||||
|
assert.equal(out.status, 0, out.stderr + '');
|
||||||
|
|
||||||
|
return Buffer.from(out.stdout.toString(), 'base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testProduceConsume() {
|
function testProduceConsume() {
|
||||||
@ -34,9 +53,7 @@ testProduceConsume();
|
|||||||
function testProduceMultiple() {
|
function testProduceMultiple() {
|
||||||
const source = getSource('original');
|
const source = getSource('original');
|
||||||
|
|
||||||
produce(source);
|
produce(source, 3);
|
||||||
produce(source);
|
|
||||||
produce(source);
|
|
||||||
}
|
}
|
||||||
testProduceMultiple();
|
testProduceMultiple();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user