From 7c07bd84d6df2776b2a31cf19e130ed55cadc0c8 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 19 Apr 2016 11:42:26 -0400 Subject: [PATCH] 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 --- test/parallel/test-vm-cached-data.js | 33 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-vm-cached-data.js b/test/parallel/test-vm-cached-data.js index 924f0826845e3a..980d391838d384 100644 --- a/test/parallel/test-vm-cached-data.js +++ b/test/parallel/test-vm-cached-data.js @@ -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'); + } + `, source]); + + assert.equal(out.status, 0, out.stderr + ''); - return script.cachedData; + return new Buffer(out.stdout.toString(), 'base64'); } function testProduceConsume() { @@ -34,9 +51,7 @@ testProduceConsume(); function testProduceMultiple() { const source = getSource('original'); - produce(source); - produce(source); - produce(source); + produce(source, 3); } testProduceMultiple();