Skip to content

Commit 7c07bd8

Browse files
committed
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: nodejs#6258
1 parent 57f0595 commit 7c07bd8

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

test/parallel/test-vm-cached-data.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,36 @@
22
require('../common');
33
const assert = require('assert');
44
const vm = require('vm');
5+
const spawnSync = require('child_process').spawnSync;
56
const Buffer = require('buffer').Buffer;
67

78
function getSource(tag) {
89
return `(function ${tag}() { return \'${tag}\'; })`;
910
}
1011

11-
function produce(source) {
12-
const script = new vm.Script(source, {
13-
produceCachedData: true
14-
});
15-
assert(!script.cachedDataProduced || script.cachedData instanceof Buffer);
12+
function produce(source, count) {
13+
if (!count)
14+
count = 1;
15+
16+
const out = spawnSync(process.execPath, [ '-p', `
17+
var assert = require('assert');
18+
var vm = require('vm');
19+
20+
for (var i = 0; i < ${count}; i++) {
21+
var script = new vm.Script(process.argv[1], {
22+
produceCachedData: true
23+
});
24+
25+
assert(!script.cachedDataProduced || script.cachedData instanceof Buffer);
26+
27+
if (script.cachedDataProduced)
28+
script.cachedData.toString('base64');
29+
}
30+
`, source]);
31+
32+
assert.equal(out.status, 0, out.stderr + '');
1633

17-
return script.cachedData;
34+
return new Buffer(out.stdout.toString(), 'base64');
1835
}
1936

2037
function testProduceConsume() {
@@ -34,9 +51,7 @@ testProduceConsume();
3451
function testProduceMultiple() {
3552
const source = getSource('original');
3653

37-
produce(source);
38-
produce(source);
39-
produce(source);
54+
produce(source, 3);
4055
}
4156
testProduceMultiple();
4257

0 commit comments

Comments
 (0)