From 10a9c005630b53a015a03bb813dbf4263fe78b5a Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 20 Mar 2015 23:55:37 +0100 Subject: [PATCH] test: fix timing issue in signal test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change sequential/test-signal-unregister so it doesn't use fixed timeouts for sending the signal and expecting the child to quit. Fixes: https://github.com/iojs/io.js/issues/1223 PR-URL: https://github.com/iojs/io.js/pull/1227 Reviewed-By: Johan Bergström --- test/fixtures/should_exit.js | 1 + test/sequential/test-signal-unregister.js | 34 +++++------------------ 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/test/fixtures/should_exit.js b/test/fixtures/should_exit.js index 6f45a904f2b..b251353f1d7 100644 --- a/test/fixtures/should_exit.js +++ b/test/fixtures/should_exit.js @@ -4,3 +4,4 @@ process.removeListener('SIGINT', tmp); setInterval(function() { process.stdout.write('keep alive\n'); }, 1000); +process.stdout.write('start\n'); diff --git a/test/sequential/test-signal-unregister.js b/test/sequential/test-signal-unregister.js index 3190ac3dce4..c3ab108dffb 100644 --- a/test/sequential/test-signal-unregister.js +++ b/test/sequential/test-signal-unregister.js @@ -1,32 +1,12 @@ var common = require('../common'); var assert = require('assert'); +var spawn = require('child_process').spawn; -var childKilled = false, done = false, - spawn = require('child_process').spawn, - util = require('util'), - child; - -var join = require('path').join; - -child = spawn(process.argv[0], [join(common.fixturesDir, 'should_exit.js')]); -child.on('exit', function() { - if (!done) childKilled = true; -}); - -setTimeout(function() { - console.log('Sending SIGINT'); +var child = spawn(process.argv[0], [common.fixturesDir + '/should_exit.js']); +child.stdout.once('data', function() { child.kill('SIGINT'); - setTimeout(function() { - console.log('Chance has been given to die'); - done = true; - if (!childKilled) { - // Cleanup - console.log('Child did not die on SIGINT, sending SIGTERM'); - child.kill('SIGTERM'); - } - }, 200); -}, 200); - -process.on('exit', function() { - assert.ok(childKilled); }); +child.on('exit', common.mustCall(function(exitCode, signalCode) { + assert.equal(exitCode, null); + assert.equal(signalCode, 'SIGINT'); +}));