From 5cc7f932b923f1ea67c3cce5553c48611edd3d15 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 12 May 2018 12:02:38 +0200 Subject: [PATCH 1/2] test: reduce runtime This refactors some tests to reduce the runtime of those. Refs: https://github.com/nodejs/node/issues/20128 --- .../test-async-wrap-pop-id-during-load.js | 14 +++++----- ...t-buffer-constructor-node-modules-paths.js | 26 ++++++++++++------- .../test-child-process-exec-encoding.js | 8 +++--- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/test/parallel/test-async-wrap-pop-id-during-load.js b/test/parallel/test-async-wrap-pop-id-during-load.js index 4f39a4fdf01b34..4cf1ef472b6037 100644 --- a/test/parallel/test-async-wrap-pop-id-during-load.js +++ b/test/parallel/test-async-wrap-pop-id-during-load.js @@ -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); +assert.ok(!/async.*hook/i.test(stderr)); +assert.ok(stderr.includes('UnhandledPromiseRejectionWarning: Error'), stderr); diff --git a/test/parallel/test-buffer-constructor-node-modules-paths.js b/test/parallel/test-buffer-constructor-node-modules-paths.js index c6a419f82ade79..f0feea5e07dafa 100644 --- a/test/parallel/test-buffer-constructor-node-modules-paths.js +++ b/test/parallel/test-buffer-constructor-node-modules-paths.js @@ -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(); + }); + 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); diff --git a/test/parallel/test-child-process-exec-encoding.js b/test/parallel/test-child-process-exec-encoding.js index 781ee51d96dcb2..d7c059a65ab4d8 100644 --- a/test/parallel/test-child-process-exec-encoding.js +++ b/test/parallel/test-child-process-exec-encoding.js @@ -1,17 +1,17 @@ 'use strict'; const common = require('../common'); -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`; From 3882ba83ec335412987cfb26b45d4a94c4d12107 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 21 May 2018 04:44:55 +0200 Subject: [PATCH 2/2] fixup: revert changes --- ...t-buffer-constructor-node-modules-paths.js | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/test/parallel/test-buffer-constructor-node-modules-paths.js b/test/parallel/test-buffer-constructor-node-modules-paths.js index f0feea5e07dafa..c6a419f82ade79 100644 --- a/test/parallel/test-buffer-constructor-node-modules-paths.js +++ b/test/parallel/test-buffer-constructor-node-modules-paths.js @@ -8,24 +8,16 @@ if (process.env.NODE_PENDING_DEPRECATION) common.skip('test does not work when NODE_PENDING_DEPRECATION is set'); function test(main, callSite, expected) { - 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' }); + const { stderr } = child_process.spawnSync(process.execPath, ['-p', ` + process.mainModule = { filename: ${JSON.stringify(main)} }; - let stderr = ''; - child.stderr.on('data', (value) => { - stderr += value.toString(); - }); - child.on('exit', () => { - if (expected) - assert(stderr.includes('[DEP0005] DeprecationWarning')); - else - assert.strictEqual(stderr.trim(), ''); - }); + 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(), ''); } test('/a/node_modules/b.js', '/a/node_modules/x.js', false);