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
Rich Trott a6d53c6779 test: add check in test-signal-handler
* Check that the removed listener is not called.
* Opportunistic `==` -> `===` change.

PR-URL: https://github.com/nodejs/node/pull/8248
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-08-26 09:34:12 -07:00

36 lines
869 B
JavaScript

'use strict';
const common = require('../common');
if (common.isWindows) {
common.skip('SIGUSR1 and SIGHUP signals are not supported');
return;
}
console.log('process.pid: ' + process.pid);
process.on('SIGUSR1', common.mustCall(function() {}));
process.on('SIGUSR1', common.mustCall(function() {
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() { common.fail('should not run'); });
process.removeAllListeners('SIGHUP');
process.on('SIGHUP', common.mustCall(function() {}));
process.kill(process.pid, 'SIGHUP');