0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-signal-handler.js
Sakthipriyan Vairamani 80a1cf7425 test: fix messages and use return to skip tests
This is a followup of https://github.com/nodejs/io.js/pull/2109.
The tests which didn't make it in #2109, are included in this patch.
The skip messages are supposed to follow the format

    1..0 # Skipped: [Actual reason why the test is skipped]

and the tests should be skipped with the return statement.

PR-URL: https://github.com/nodejs/io.js/pull/2290
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-08-03 21:32:48 +05:30

52 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
if (common.isWindows) {
console.log('1..0 # Skipped: SIGUSR1 and SIGHUP signals are not supported');
return;
}
console.log('process.pid: ' + process.pid);
var first = 0,
second = 0;
var sighup = false;
process.on('SIGUSR1', function() {
console.log('Interrupted by SIGUSR1');
first += 1;
});
process.on('SIGUSR1', function() {
second += 1;
setTimeout(function() {
console.log('End.');
process.exit(0);
}, 5);
});
var i = 0;
setInterval(function() {
console.log('running process...' + ++i);
if (i == 5) {
process.kill(process.pid, 'SIGUSR1');
}
}, 1);
// Test on condition where a watcher for SIGNAL
// has been previously registered, and `process.listeners(SIGNAL).length === 1`
process.on('SIGHUP', function() {});
process.removeAllListeners('SIGHUP');
process.on('SIGHUP', function() { sighup = true; });
process.kill(process.pid, 'SIGHUP');
process.on('exit', function() {
assert.equal(1, first);
assert.equal(1, second);
assert.equal(true, sighup);
});