1// Flags: --experimental-abortcontroller 2'use strict'; 3const common = require('../common'); 4 5if (!common.hasCrypto) 6 common.skip('missing crypto'); 7 8const fixtures = require('../common/fixtures'); 9const https = require('https'); 10const assert = require('assert'); 11const { once } = require('events'); 12 13const options = { 14 key: fixtures.readKey('agent1-key.pem'), 15 cert: fixtures.readKey('agent1-cert.pem') 16}; 17 18(async () => { 19 const { port, server } = await new Promise((resolve) => { 20 const server = https.createServer(options, () => {}); 21 server.listen(0, () => resolve({ port: server.address().port, server })); 22 }); 23 try { 24 const ac = new AbortController(); 25 const req = https.request({ 26 host: 'localhost', 27 port, 28 path: '/', 29 method: 'GET', 30 rejectUnauthorized: false, 31 signal: ac.signal, 32 }); 33 process.nextTick(() => ac.abort()); 34 const [ err ] = await once(req, 'error'); 35 assert.strictEqual(err.name, 'AbortError'); 36 assert.strictEqual(err.code, 'ABORT_ERR'); 37 } finally { 38 server.close(); 39 } 40})().then(common.mustCall()); 41