summaryrefslogtreecommitdiff
path: root/test/parallel/test-async-hooks-top-level-clearimmediate.js
blob: e7a5d8f5606118d5c4844718f51b832751dc4f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict';

// Regression test for https://github.com/nodejs/node/issues/13262

const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');

let seenId, seenResource;

async_hooks.createHook({
  init: common.mustCall((id, provider, triggerAsyncId, resource) => {
    seenId = id;
    seenResource = resource;
    assert.strictEqual(provider, 'Immediate');
    assert.strictEqual(triggerAsyncId, 1);
  }),
  before: common.mustNotCall(),
  after: common.mustNotCall(),
  destroy: common.mustCall((id) => {
    assert.strictEqual(seenId, id);
  })
}).enable();

const immediate = setImmediate(common.mustNotCall());
assert.strictEqual(immediate, seenResource);
clearImmediate(immediate);