node/test/parallel/test-async-hooks-recursive-stack-runInAsyncScope.js
Antoine du Hamel e72761fe5e
test: ensure assertions are reached on more tests
PR-URL: https://github.com/nodejs/node/pull/60485
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-11-06 09:47:01 +01:00

21 lines
668 B
JavaScript

'use strict';
const common = 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.runInAsyncScope(common.mustCall(() => {
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());
}));
}
recurse(1000);