node/test/parallel/test-async-wrap-destroyid.js
Daniel Bevenius da8641f3b4 src: move process.binding('async_wrap') internal
This commit makes the async_wrap builtin an internal builtin, and
changes usage of the builtin from using process.binding('async_wrap')
to use internalBinding instead.

Refs: https://github.com/nodejs/node/issues/22160

PR-URL: https://github.com/nodejs/node/pull/22469
Refs: https://github.com/nodejs/node/issues/22160
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2018-08-27 05:42:55 +02:00

40 lines
910 B
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const { internalBinding } = require('internal/test/binding');
const async_wrap = internalBinding('async_wrap');
const assert = require('assert');
const async_hooks = require('async_hooks');
const RUNS = 5;
let test_id = null;
let run_cntr = 0;
let hooks = null;
process.on('beforeExit', common.mustCall(() => {
process.removeAllListeners('uncaughtException');
hooks.disable();
assert.strictEqual(test_id, null);
assert.strictEqual(run_cntr, RUNS);
}));
hooks = async_hooks.createHook({
destroy(id) {
if (id === test_id) {
run_cntr++;
test_id = null;
}
},
}).enable();
(function runner(n) {
assert.strictEqual(test_id, null);
if (n <= 0) return;
test_id = (Math.random() * 1e9) >>> 0;
async_wrap.queueDestroyAsyncId(test_id);
setImmediate(common.mustCall(runner), n - 1);
})(RUNS);