From f44b3c12e57f5c1ec1490116edc8e55327f78b02 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Sat, 28 Nov 2020 20:01:51 +0200 Subject: [PATCH] https: add abortcontroller test PR-URL: https://github.com/nodejs/node/pull/36307 Reviewed-By: Antoine du Hamel Reviewed-By: Rich Trott Reviewed-By: James M Snell --- test/parallel/test-https-abortcontroller.js | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/parallel/test-https-abortcontroller.js diff --git a/test/parallel/test-https-abortcontroller.js b/test/parallel/test-https-abortcontroller.js new file mode 100644 index 00000000000000..3da2ab9ce25c28 --- /dev/null +++ b/test/parallel/test-https-abortcontroller.js @@ -0,0 +1,40 @@ +// Flags: --experimental-abortcontroller +'use strict'; +const common = require('../common'); + +if (!common.hasCrypto) + common.skip('missing crypto'); + +const fixtures = require('../common/fixtures'); +const https = require('https'); +const assert = require('assert'); +const { once } = require('events'); + +const options = { + key: fixtures.readKey('agent1-key.pem'), + cert: fixtures.readKey('agent1-cert.pem') +}; + +(async () => { + const { port, server } = await new Promise((resolve) => { + const server = https.createServer(options, () => {}); + server.listen(0, () => resolve({ port: server.address().port, server })); + }); + try { + const ac = new AbortController(); + const req = https.request({ + host: 'localhost', + port, + path: '/', + method: 'GET', + rejectUnauthorized: false, + signal: ac.signal, + }); + process.nextTick(() => ac.abort()); + const [ err ] = await once(req, 'error'); + assert.strictEqual(err.name, 'AbortError'); + assert.strictEqual(err.code, 'ABORT_ERR'); + } finally { + server.close(); + } +})().then(common.mustCall());