|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const initHooks = require('./init-hooks'); |
| 6 | +const { checkInvocations } = require('./hook-checks'); |
| 7 | +const TIMEOUT = common.platformTimeout(100); |
| 8 | + |
| 9 | +const hooks = initHooks(); |
| 10 | +hooks.enable(); |
| 11 | + |
| 12 | +setInterval(common.mustCall(ontimeout), TIMEOUT); |
| 13 | +const as = hooks.activitiesOfTypes('Timeout'); |
| 14 | +assert.strictEqual(as.length, 1); |
| 15 | +const t1 = as[0]; |
| 16 | +assert.strictEqual(t1.type, 'Timeout'); |
| 17 | +assert.strictEqual(typeof t1.uid, 'number'); |
| 18 | +assert.strictEqual(typeof t1.triggerAsyncId, 'number'); |
| 19 | +checkInvocations(t1, { init: 1 }, 't1: when timer installed'); |
| 20 | + |
| 21 | +function ontimeout() { |
| 22 | + checkInvocations(t1, { init: 1, before: 1 }, 't1: when first timer fired'); |
| 23 | + |
| 24 | + throw new Error('setInterval Error'); |
| 25 | +} |
| 26 | + |
| 27 | +process.once('uncaughtException', common.mustCall((err) => { |
| 28 | + assert.strictEqual(err.message, 'setInterval Error'); |
| 29 | +})); |
| 30 | + |
| 31 | +process.on('exit', () => { |
| 32 | + hooks.disable(); |
| 33 | + hooks.sanityCheck('Timeout'); |
| 34 | + |
| 35 | + checkInvocations(t1, { init: 1, before: 1, after: 1, destroy: 1 }, |
| 36 | + 't1: when process exits'); |
| 37 | +}); |
0 commit comments