2016-11-22 17:13:44 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2018-10-12 19:35:08 +02:00
|
|
|
const tick = require('../common/tick');
|
2016-11-22 17:13:44 +01:00
|
|
|
const initHooks = require('./init-hooks');
|
|
|
|
const { checkInvocations } = require('./hook-checks');
|
|
|
|
|
|
|
|
const hooks = initHooks();
|
|
|
|
hooks.enable();
|
|
|
|
|
2019-03-22 03:44:26 +01:00
|
|
|
// Install first immediate
|
2016-11-22 17:13:44 +01:00
|
|
|
setImmediate(common.mustCall(onimmediate));
|
|
|
|
|
|
|
|
const as = hooks.activitiesOfTypes('Immediate');
|
2017-05-26 17:53:06 +02:00
|
|
|
assert.strictEqual(as.length, 1);
|
2016-11-22 17:13:44 +01:00
|
|
|
const imd1 = as[0];
|
2017-05-26 17:53:06 +02:00
|
|
|
assert.strictEqual(imd1.type, 'Immediate');
|
|
|
|
assert.strictEqual(typeof imd1.uid, 'number');
|
2017-06-14 12:39:53 +02:00
|
|
|
assert.strictEqual(typeof imd1.triggerAsyncId, 'number');
|
2016-11-22 17:13:44 +01:00
|
|
|
checkInvocations(imd1, { init: 1 },
|
|
|
|
'imd1: when first set immediate installed');
|
|
|
|
|
|
|
|
let imd2;
|
|
|
|
|
|
|
|
function onimmediate() {
|
|
|
|
let as = hooks.activitiesOfTypes('Immediate');
|
2017-05-26 17:53:06 +02:00
|
|
|
assert.strictEqual(as.length, 1);
|
2016-11-22 17:13:44 +01:00
|
|
|
checkInvocations(imd1, { init: 1, before: 1 },
|
|
|
|
'imd1: when first set immediate triggered');
|
|
|
|
|
2019-03-22 03:44:26 +01:00
|
|
|
// Install second immediate
|
2016-11-22 17:13:44 +01:00
|
|
|
setImmediate(common.mustCall(onimmediateTwo));
|
|
|
|
as = hooks.activitiesOfTypes('Immediate');
|
2017-05-26 17:53:06 +02:00
|
|
|
assert.strictEqual(as.length, 2);
|
2016-11-22 17:13:44 +01:00
|
|
|
imd2 = as[1];
|
2017-05-26 17:53:06 +02:00
|
|
|
assert.strictEqual(imd2.type, 'Immediate');
|
|
|
|
assert.strictEqual(typeof imd2.uid, 'number');
|
2017-06-14 12:39:53 +02:00
|
|
|
assert.strictEqual(typeof imd2.triggerAsyncId, 'number');
|
2016-11-22 17:13:44 +01:00
|
|
|
checkInvocations(imd1, { init: 1, before: 1 },
|
|
|
|
'imd1: when second set immediate installed');
|
|
|
|
checkInvocations(imd2, { init: 1 },
|
|
|
|
'imd2: when second set immediate installed');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onimmediateTwo() {
|
|
|
|
checkInvocations(imd1, { init: 1, before: 1, after: 1, destroy: 1 },
|
|
|
|
'imd1: when second set immediate triggered');
|
|
|
|
checkInvocations(imd2, { init: 1, before: 1 },
|
|
|
|
'imd2: when second set immediate triggered');
|
|
|
|
tick(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on('exit', onexit);
|
|
|
|
|
|
|
|
function onexit() {
|
|
|
|
hooks.disable();
|
|
|
|
hooks.sanityCheck('Immediate');
|
|
|
|
checkInvocations(imd1, { init: 1, before: 1, after: 1, destroy: 1 },
|
|
|
|
'imd1: when process exits');
|
|
|
|
checkInvocations(imd2, { init: 1, before: 1, after: 1, destroy: 1 },
|
|
|
|
'imd2: when process exits');
|
|
|
|
}
|