11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst child_process = require('child_process'); 51cb0ef41Sopenharmony_ciconst test_async = require(`./build/${common.buildType}/test_async`); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst testException = 'test_async_cb_exception'; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// Exception thrown from async completion callback. 101cb0ef41Sopenharmony_ci// (Tested in a spawned process because the exception is fatal.) 111cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') { 121cb0ef41Sopenharmony_ci test_async.Test(1, {}, common.mustCall(function() { 131cb0ef41Sopenharmony_ci throw new Error(testException); 141cb0ef41Sopenharmony_ci })); 151cb0ef41Sopenharmony_ci return; 161cb0ef41Sopenharmony_ci} 171cb0ef41Sopenharmony_ciconst p = child_process.spawnSync( 181cb0ef41Sopenharmony_ci process.execPath, [ __filename, 'child' ]); 191cb0ef41Sopenharmony_ciassert.ifError(p.error); 201cb0ef41Sopenharmony_ciassert.ok(p.stderr.toString().includes(testException)); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci// Successful async execution and completion callback. 231cb0ef41Sopenharmony_citest_async.Test(5, {}, common.mustCall(function(err, val) { 241cb0ef41Sopenharmony_ci assert.strictEqual(err, null); 251cb0ef41Sopenharmony_ci assert.strictEqual(val, 10); 261cb0ef41Sopenharmony_ci process.nextTick(common.mustCall()); 271cb0ef41Sopenharmony_ci})); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci// Async work item cancellation with callback. 301cb0ef41Sopenharmony_citest_async.TestCancel(common.mustCall()); 31