• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const tick = require('../common/tick');
6const initHooks = require('./init-hooks');
7const { checkInvocations } = require('./hook-checks');
8const fs = require('fs');
9
10if (!common.isMainThread)
11  common.skip('Worker bootstrapping works differently -> different async IDs');
12
13const hooks = initHooks();
14
15hooks.enable();
16fs.readFile(__filename, common.mustCall(onread));
17
18function onread() {
19  const as = hooks.activitiesOfTypes('FSREQCALLBACK');
20  let lastParent = 1;
21  for (let i = 0; i < as.length; i++) {
22    const a = as[i];
23    assert.strictEqual(a.type, 'FSREQCALLBACK');
24    assert.strictEqual(typeof a.uid, 'number');
25    assert.strictEqual(a.triggerAsyncId, lastParent);
26    lastParent = a.uid;
27  }
28  checkInvocations(as[0], { init: 1, before: 1, after: 1, destroy: 1 },
29                   'reqwrap[0]: while in onread callback');
30  checkInvocations(as[1], { init: 1, before: 1, after: 1, destroy: 1 },
31                   'reqwrap[1]: while in onread callback');
32  checkInvocations(as[2], { init: 1, before: 1, after: 1, destroy: 1 },
33                   'reqwrap[2]: while in onread callback');
34
35  // This callback is called from within the last fs req callback therefore
36  // the last req is still going and after/destroy haven't been called yet
37  checkInvocations(as[3], { init: 1, before: 1 },
38                   'reqwrap[3]: while in onread callback');
39  tick(2);
40}
41
42process.on('exit', onexit);
43
44function onexit() {
45  hooks.disable();
46  hooks.sanityCheck('FSREQCALLBACK');
47  const as = hooks.activitiesOfTypes('FSREQCALLBACK');
48  const a = as.pop();
49  checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 },
50                   'when process exits');
51}
52