node/test/parallel/test-async-hooks-async-await.js
Antoine du Hamel e50cbc1abd
test: enforce better never-settling-promise detection
Tests should be explicit regarding whether a promise is expected to
settle, and the test should fail when the behavior does not meet
expectations.

PR-URL: https://github.com/nodejs/node/pull/60976
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
2025-12-10 23:55:36 +00:00

27 lines
689 B
JavaScript

// Test async-hooks fired on right
// asyncIds & triggerAsyncId for async-await
'use strict';
const common = require('../common');
const async_hooks = require('async_hooks');
const assert = require('assert');
const asyncIds = [];
async_hooks.createHook({
init: (asyncId, type, triggerAsyncId) => {
asyncIds.push([triggerAsyncId, asyncId]);
}
}).enable();
async function main() {
await null;
}
main().then(() => {
// Verify the relationships between async ids
// 1 => 2, 2 => 3 etc
assert.strictEqual(asyncIds[0][1], asyncIds[1][0]);
assert.strictEqual(asyncIds[0][1], asyncIds[3][0]);
assert.strictEqual(asyncIds[1][1], asyncIds[2][0]);
}).then(common.mustCall());