mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
Signed-off-by: ishabi <ilyasshabi94@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65982 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Bryan English <bryan@bryanenglish.com>
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
'use strict';
|
|
const common = require('../../common');
|
|
const assert = require('assert');
|
|
const child_process = require('child_process');
|
|
const dc = require('diagnostics_channel');
|
|
const test_async = require(`./build/${common.buildType}/test_async`);
|
|
|
|
const testException = 'test_async_cb_exception';
|
|
|
|
// Exception thrown from async completion callback.
|
|
// (Tested in a spawned process because the exception is fatal.)
|
|
if (process.argv[2] === 'child') {
|
|
test_async.Test(1, {}, common.mustCall(function() {
|
|
throw new Error(testException);
|
|
}));
|
|
return;
|
|
}
|
|
const p = child_process.spawnSync(
|
|
process.execPath, [ __filename, 'child' ]);
|
|
assert.ifError(p.error);
|
|
assert.ok(p.stderr.toString().includes(testException));
|
|
|
|
// Successful async execution and completion callback.
|
|
test_async.Test(5, {}, common.mustCall(function(err, val) {
|
|
assert.strictEqual(err, null);
|
|
assert.strictEqual(val, 10);
|
|
process.nextTick(common.mustCall());
|
|
}));
|
|
|
|
// Async work item cancellation with callback.
|
|
const events = [];
|
|
const onThreadPoolWork = (event) => events.push(event);
|
|
dc.subscribe('uv.threadpool.work.node_api', onThreadPoolWork);
|
|
test_async.TestCancel(common.mustCall(() => {
|
|
dc.unsubscribe('uv.threadpool.work.node_api', onThreadPoolWork);
|
|
const event = events.find(({ started, ended }) =>
|
|
started === null && ended === null);
|
|
assert.ok(event);
|
|
}));
|