• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../../common');
3const assert = require('assert');
4const child_process = require('child_process');
5const test_async = require(`./build/${common.buildType}/test_async`);
6
7const testException = 'test_async_cb_exception';
8
9// Exception thrown from async completion callback.
10// (Tested in a spawned process because the exception is fatal.)
11if (process.argv[2] === 'child') {
12  test_async.Test(1, {}, common.mustCall(function() {
13    throw new Error(testException);
14  }));
15  return;
16}
17const p = child_process.spawnSync(
18  process.execPath, [ __filename, 'child' ]);
19assert.ifError(p.error);
20assert.ok(p.stderr.toString().includes(testException));
21
22// Successful async execution and completion callback.
23test_async.Test(5, {}, common.mustCall(function(err, val) {
24  assert.strictEqual(err, null);
25  assert.strictEqual(val, 10);
26  process.nextTick(common.mustCall());
27}));
28
29// Async work item cancellation with callback.
30test_async.TestCancel(common.mustCall());
31