2017-03-28 02:06:58 -07:00
|
|
|
'use strict';
|
|
|
|
const common = require('../../common');
|
|
|
|
const assert = require('assert');
|
2017-05-04 15:24:44 -07:00
|
|
|
const child_process = require('child_process');
|
2018-01-23 21:49:25 +11:00
|
|
|
const test_async = require(`./build/${common.buildType}/test_async`);
|
2017-03-28 02:06:58 -07:00
|
|
|
|
2017-05-04 15:24:44 -07:00
|
|
|
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') {
|
2017-08-08 20:18:16 +02:00
|
|
|
test_async.Test(1, {}, common.mustCall(function() {
|
2017-05-04 15:24:44 -07:00
|
|
|
throw new Error(testException);
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const p = child_process.spawnSync(
|
2017-08-18 13:30:05 +03:00
|
|
|
process.execPath, [ __filename, 'child' ]);
|
2017-05-04 15:24:44 -07:00
|
|
|
assert.ifError(p.error);
|
|
|
|
assert.ok(p.stderr.toString().includes(testException));
|
|
|
|
|
|
|
|
// Successful async execution and completion callback.
|
2017-08-08 20:18:16 +02:00
|
|
|
test_async.Test(5, {}, common.mustCall(function(err, val) {
|
2017-03-28 02:06:58 -07:00
|
|
|
assert.strictEqual(err, null);
|
|
|
|
assert.strictEqual(val, 10);
|
2017-04-27 17:27:05 -07:00
|
|
|
process.nextTick(common.mustCall());
|
2017-03-28 02:06:58 -07:00
|
|
|
}));
|
2017-04-21 18:10:39 -04:00
|
|
|
|
2017-05-04 15:24:44 -07:00
|
|
|
// Async work item cancellation with callback.
|
2017-04-27 17:27:05 -07:00
|
|
|
test_async.TestCancel(common.mustCall());
|