Skip to content

Commit f44b3c1

Browse files
benjamingrtargos
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 f5e8f12 commit f44b3c1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Flags: --experimental-abortcontroller
2+
'use strict';
3+
const common = require('../common');
4+
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
8+
const fixtures = require('../common/fixtures');
9+
const https = require('https');
10+
const assert = require('assert');
11+
const { once } = require('events');
12+
13+
const 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());

0 commit comments

Comments
 (0)