Many of the tests use variables to track when callback functions are invoked or events are emitted. These variables are then asserted on process exit. This commit replaces this pattern in straightforward cases with common.mustCall(). This makes the tests easier to reason about, leads to a net reduction in lines of code, and uncovered a few bugs in tests. This commit also replaces some callbacks that should never be called with common.fail(). PR-URL: https://github.com/nodejs/node/pull/7753 Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
35 lines
869 B
JavaScript
35 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');
|