Skip to content

Commit 4127eb2

Browse files
benjamingrdanielleadams
authored andcommitted
https: add abortcontroller test
PR-URL: #36307 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8d8d226 commit 4127eb2

File tree

1 file changed

+39
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)