1// Flags: --experimental-abortcontroller 2'use strict'; 3const common = require('../common'); 4const assert = require('assert'); 5const exec = require('child_process').exec; 6const { promisify } = require('util'); 7 8const execPromisifed = promisify(exec); 9const invalidArgTypeError = { 10 code: 'ERR_INVALID_ARG_TYPE', 11 name: 'TypeError' 12}; 13 14const waitCommand = common.isLinux ? 15 'sleep 2m' : 16 `${process.execPath} -e "setInterval(()=>{}, 99)"`; 17 18{ 19 const ac = new AbortController(); 20 const signal = ac.signal; 21 const promise = execPromisifed(waitCommand, { signal }); 22 assert.rejects(promise, /AbortError/, 'post aborted sync signal failed') 23 .then(common.mustCall()); 24 ac.abort(); 25} 26 27{ 28 assert.throws(() => { 29 execPromisifed(waitCommand, { signal: {} }); 30 }, invalidArgTypeError); 31} 32 33{ 34 function signal() {} 35 assert.throws(() => { 36 execPromisifed(waitCommand, { signal }); 37 }, invalidArgTypeError); 38} 39 40{ 41 const ac = new AbortController(); 42 const { signal } = ac; 43 ac.abort(); 44 const promise = execPromisifed(waitCommand, { signal }); 45 46 assert.rejects(promise, /AbortError/, 'pre aborted signal failed') 47 .then(common.mustCall()); 48} 49