11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 81cb0ef41Sopenharmony_ciconst https = require('https'); 91cb0ef41Sopenharmony_ciconst assert = require('assert'); 101cb0ef41Sopenharmony_ciconst { once, getEventListeners } = require('events'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst options = { 131cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 141cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem') 151cb0ef41Sopenharmony_ci}; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci// Check async post-aborted 181cb0ef41Sopenharmony_ci(async () => { 191cb0ef41Sopenharmony_ci const { port, server } = await new Promise((resolve) => { 201cb0ef41Sopenharmony_ci const server = https.createServer(options, () => {}); 211cb0ef41Sopenharmony_ci server.listen(0, () => resolve({ port: server.address().port, server })); 221cb0ef41Sopenharmony_ci }); 231cb0ef41Sopenharmony_ci try { 241cb0ef41Sopenharmony_ci const ac = new AbortController(); 251cb0ef41Sopenharmony_ci const req = https.request({ 261cb0ef41Sopenharmony_ci host: 'localhost', 271cb0ef41Sopenharmony_ci port, 281cb0ef41Sopenharmony_ci path: '/', 291cb0ef41Sopenharmony_ci method: 'GET', 301cb0ef41Sopenharmony_ci rejectUnauthorized: false, 311cb0ef41Sopenharmony_ci signal: ac.signal, 321cb0ef41Sopenharmony_ci }); 331cb0ef41Sopenharmony_ci assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 1); 341cb0ef41Sopenharmony_ci process.nextTick(() => ac.abort()); 351cb0ef41Sopenharmony_ci const [ err ] = await once(req, 'error'); 361cb0ef41Sopenharmony_ci assert.strictEqual(err.name, 'AbortError'); 371cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'ABORT_ERR'); 381cb0ef41Sopenharmony_ci } finally { 391cb0ef41Sopenharmony_ci server.close(); 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci})().then(common.mustCall()); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci// Check sync post-aborted signal 441cb0ef41Sopenharmony_ci(async () => { 451cb0ef41Sopenharmony_ci const { port, server } = await new Promise((resolve) => { 461cb0ef41Sopenharmony_ci const server = https.createServer(options, () => {}); 471cb0ef41Sopenharmony_ci server.listen(0, () => resolve({ port: server.address().port, server })); 481cb0ef41Sopenharmony_ci }); 491cb0ef41Sopenharmony_ci try { 501cb0ef41Sopenharmony_ci const ac = new AbortController(); 511cb0ef41Sopenharmony_ci const { signal } = ac; 521cb0ef41Sopenharmony_ci const req = https.request({ 531cb0ef41Sopenharmony_ci host: 'localhost', 541cb0ef41Sopenharmony_ci port, 551cb0ef41Sopenharmony_ci path: '/', 561cb0ef41Sopenharmony_ci method: 'GET', 571cb0ef41Sopenharmony_ci rejectUnauthorized: false, 581cb0ef41Sopenharmony_ci signal, 591cb0ef41Sopenharmony_ci }); 601cb0ef41Sopenharmony_ci assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 1); 611cb0ef41Sopenharmony_ci ac.abort(); 621cb0ef41Sopenharmony_ci const [ err ] = await once(req, 'error'); 631cb0ef41Sopenharmony_ci assert.strictEqual(err.name, 'AbortError'); 641cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'ABORT_ERR'); 651cb0ef41Sopenharmony_ci } finally { 661cb0ef41Sopenharmony_ci server.close(); 671cb0ef41Sopenharmony_ci } 681cb0ef41Sopenharmony_ci})().then(common.mustCall()); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci// Check pre-aborted signal 711cb0ef41Sopenharmony_ci(async () => { 721cb0ef41Sopenharmony_ci const { port, server } = await new Promise((resolve) => { 731cb0ef41Sopenharmony_ci const server = https.createServer(options, () => {}); 741cb0ef41Sopenharmony_ci server.listen(0, () => resolve({ port: server.address().port, server })); 751cb0ef41Sopenharmony_ci }); 761cb0ef41Sopenharmony_ci try { 771cb0ef41Sopenharmony_ci const ac = new AbortController(); 781cb0ef41Sopenharmony_ci const { signal } = ac; 791cb0ef41Sopenharmony_ci ac.abort(); 801cb0ef41Sopenharmony_ci const req = https.request({ 811cb0ef41Sopenharmony_ci host: 'localhost', 821cb0ef41Sopenharmony_ci port, 831cb0ef41Sopenharmony_ci path: '/', 841cb0ef41Sopenharmony_ci method: 'GET', 851cb0ef41Sopenharmony_ci rejectUnauthorized: false, 861cb0ef41Sopenharmony_ci signal, 871cb0ef41Sopenharmony_ci }); 881cb0ef41Sopenharmony_ci assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 0); 891cb0ef41Sopenharmony_ci const [ err ] = await once(req, 'error'); 901cb0ef41Sopenharmony_ci assert.strictEqual(err.name, 'AbortError'); 911cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'ABORT_ERR'); 921cb0ef41Sopenharmony_ci } finally { 931cb0ef41Sopenharmony_ci server.close(); 941cb0ef41Sopenharmony_ci } 951cb0ef41Sopenharmony_ci})().then(common.mustCall()); 96