2016-11-22 13:13:44 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2017-06-01 19:06:07 -04:00
|
|
|
if (common.isWindows) {
|
|
|
|
common.skip('no signals on Windows');
|
|
|
|
}
|
|
|
|
|
2016-11-22 13:13:44 -03:00
|
|
|
const initHooks = require('./init-hooks');
|
|
|
|
const verifyGraph = require('./verify-graph');
|
2017-12-06 14:57:13 -08:00
|
|
|
const { exec } = require('child_process');
|
2016-11-22 13:13:44 -03:00
|
|
|
|
|
|
|
const hooks = initHooks();
|
|
|
|
|
|
|
|
hooks.enable();
|
2017-12-06 14:57:13 -08:00
|
|
|
const interval = setInterval(() => {}, 9999); // keep event loop open
|
2016-11-22 13:13:44 -03:00
|
|
|
process.on('SIGUSR2', common.mustCall(onsigusr2, 2));
|
|
|
|
|
|
|
|
let count = 0;
|
2017-07-16 15:36:22 +08:00
|
|
|
exec(`kill -USR2 ${process.pid}`);
|
2016-11-22 13:13:44 -03:00
|
|
|
|
|
|
|
function onsigusr2() {
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (count === 1) {
|
|
|
|
// trigger same signal handler again
|
2017-07-16 15:36:22 +08:00
|
|
|
exec(`kill -USR2 ${process.pid}`);
|
2016-11-22 13:13:44 -03:00
|
|
|
} else {
|
|
|
|
// install another signal handler
|
|
|
|
process.removeAllListeners('SIGUSR2');
|
|
|
|
process.on('SIGUSR2', common.mustCall(onsigusr2Again));
|
|
|
|
|
2017-07-16 15:36:22 +08:00
|
|
|
exec(`kill -USR2 ${process.pid}`);
|
2016-11-22 13:13:44 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 14:57:13 -08:00
|
|
|
function onsigusr2Again() {
|
|
|
|
clearInterval(interval); // let the event loop close
|
|
|
|
}
|
2016-11-22 13:13:44 -03:00
|
|
|
|
|
|
|
process.on('exit', onexit);
|
|
|
|
|
|
|
|
function onexit() {
|
|
|
|
hooks.disable();
|
|
|
|
verifyGraph(
|
|
|
|
hooks,
|
2017-06-14 12:39:53 +02:00
|
|
|
[ { type: 'SIGNALWRAP', id: 'signal:1', triggerAsyncId: null },
|
|
|
|
{ type: 'PROCESSWRAP', id: 'process:1', triggerAsyncId: null },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:1', triggerAsyncId: null },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:2', triggerAsyncId: null },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:3', triggerAsyncId: null },
|
|
|
|
{ type: 'PROCESSWRAP', id: 'process:2', triggerAsyncId: 'signal:1' },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:4', triggerAsyncId: 'signal:1' },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:5', triggerAsyncId: 'signal:1' },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:6', triggerAsyncId: 'signal:1' },
|
|
|
|
{ type: 'SIGNALWRAP', id: 'signal:2', triggerAsyncId: 'signal:1' },
|
|
|
|
{ type: 'PROCESSWRAP', id: 'process:3', triggerAsyncId: 'signal:1' },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:7', triggerAsyncId: 'signal:1' },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:8', triggerAsyncId: 'signal:1' },
|
|
|
|
{ type: 'PIPEWRAP', id: 'pipe:9', triggerAsyncId: 'signal:1' } ]
|
2016-11-22 13:13:44 -03:00
|
|
|
);
|
|
|
|
}
|