Skip to content

Commit 10a9c00

Browse files
committed
test: fix timing issue in signal test
Change sequential/test-signal-unregister so it doesn't use fixed timeouts for sending the signal and expecting the child to quit. Fixes: #1223 PR-URL: #1227 Reviewed-By: Johan Bergström <[email protected]>
1 parent cf081a4 commit 10a9c00

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

test/fixtures/should_exit.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ process.removeListener('SIGINT', tmp);
44
setInterval(function() {
55
process.stdout.write('keep alive\n');
66
}, 1000);
7+
process.stdout.write('start\n');
+7-27
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
11
var common = require('../common');
22
var assert = require('assert');
3+
var spawn = require('child_process').spawn;
34

4-
var childKilled = false, done = false,
5-
spawn = require('child_process').spawn,
6-
util = require('util'),
7-
child;
8-
9-
var join = require('path').join;
10-
11-
child = spawn(process.argv[0], [join(common.fixturesDir, 'should_exit.js')]);
12-
child.on('exit', function() {
13-
if (!done) childKilled = true;
14-
});
15-
16-
setTimeout(function() {
17-
console.log('Sending SIGINT');
5+
var child = spawn(process.argv[0], [common.fixturesDir + '/should_exit.js']);
6+
child.stdout.once('data', function() {
187
child.kill('SIGINT');
19-
setTimeout(function() {
20-
console.log('Chance has been given to die');
21-
done = true;
22-
if (!childKilled) {
23-
// Cleanup
24-
console.log('Child did not die on SIGINT, sending SIGTERM');
25-
child.kill('SIGTERM');
26-
}
27-
}, 200);
28-
}, 200);
29-
30-
process.on('exit', function() {
31-
assert.ok(childKilled);
328
});
9+
child.on('exit', common.mustCall(function(exitCode, signalCode) {
10+
assert.equal(exitCode, null);
11+
assert.equal(signalCode, 'SIGINT');
12+
}));

0 commit comments

Comments
 (0)