summaryrefslogtreecommitdiff
path: root/test/parallel/test-async-hooks-recursive-stack.js
blob: 7ab73dc1bf4538f506bc08909de722438390d6a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';
require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');

// This test verifies that the async ID stack can grow indefinitely.

function recurse(n) {
  const a = new async_hooks.AsyncResource('foobar');
  a.emitBefore();
  assert.strictEqual(a.asyncId(), async_hooks.executionAsyncId());
  assert.strictEqual(a.triggerAsyncId(), async_hooks.triggerAsyncId());
  if (n >= 0)
    recurse(n - 1);
  assert.strictEqual(a.asyncId(), async_hooks.executionAsyncId());
  assert.strictEqual(a.triggerAsyncId(), async_hooks.triggerAsyncId());
  a.emitAfter();
}

recurse(1000);