From 74c772c3eb6829d2b5c07373ebcb51e7d9dcc4d1 Mon Sep 17 00:00:00 2001 From: Wyatt Preul Date: Thu, 29 Sep 2016 10:56:15 -0500 Subject: [PATCH] test: run faster and cleanup after run PR-URL: https://github.com/nodejs/node/pull/8848 Reviewed-By: James M Snell Reviewed-By: Fedor Indutny Reviewed-By: Matthew Loring Reviewed-By: Ilkka Myller --- test/fixtures/tick-processor-base.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/fixtures/tick-processor-base.js b/test/fixtures/tick-processor-base.js index 8e0005ff7d8b99..ca67a0f7e967b4 100644 --- a/test/fixtures/tick-processor-base.js +++ b/test/fixtures/tick-processor-base.js @@ -7,7 +7,7 @@ const path = require('path'); common.refreshTmpDir(); const LOG_FILE = path.join(common.tmpDir, 'tick-processor.log'); -const RETRY_TIMEOUT = 750; +const RETRY_TIMEOUT = 150; function runTest(test) { const proc = cp.spawn(process.execPath, [ @@ -16,7 +16,7 @@ function runTest(test) { '--prof', '-pe', test.code ], { - stdio: [ null, 'pipe', 'inherit' ] + stdio: [ 'ignore', 'pipe', 'inherit' ] }); let ticks = ''; @@ -37,19 +37,25 @@ function match(pattern, parent, ticks) { '--call-graph-size=10', LOG_FILE ], { - stdio: [ null, 'pipe', 'inherit' ] + stdio: [ 'ignore', 'pipe', 'inherit' ] }); let out = ''; proc.stdout.on('data', chunk => out += chunk); - proc.stdout.on('end', () => { - // Retry after timeout - if (!pattern.test(out)) - return setTimeout(() => match(pattern, parent, ticks), RETRY_TIMEOUT); + proc.stdout.once('end', () => { + proc.once('exit', () => { + fs.unlinkSync(LOG_FILE); - parent.kill('SIGTERM'); + // Retry after timeout + if (!pattern.test(out)) + return setTimeout(() => match(pattern, parent, ticks), RETRY_TIMEOUT); - fs.unlinkSync(LOG_FILE); + parent.stdout.removeAllListeners(); + parent.kill(); + }); + + proc.stdout.removeAllListeners(); + proc.kill(); }); }