Skip to content

Commit 7705360

Browse files
Braydon FullerMyles Borins
Braydon Fuller
authored and
Myles Borins
committed
test: add test for https server close event
PR-URL: #5106 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent 9d6623e commit 7705360

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/parallel/test-https-close.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
const common = require('../common');
3+
const fs = require('fs');
4+
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: missing crypto');
7+
return;
8+
}
9+
const https = require('https');
10+
11+
const options = {
12+
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
13+
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
14+
};
15+
16+
var connections = {};
17+
18+
var server = https.createServer(options, function(req, res) {
19+
var interval = setInterval(function() {
20+
res.write('data');
21+
}, 1000);
22+
interval.unref();
23+
});
24+
25+
server.on('connection', function(connection) {
26+
var key = connection.remoteAddress + ':' + connection.remotePort;
27+
connection.on('close', function() {
28+
delete connections[key];
29+
});
30+
connections[key] = connection;
31+
});
32+
33+
function shutdown() {
34+
server.close(common.mustCall(function() {}));
35+
36+
for (var key in connections) {
37+
connections[key].destroy();
38+
delete connections[key];
39+
}
40+
}
41+
42+
server.listen(common.PORT, function() {
43+
var requestOptions = {
44+
hostname: '127.0.0.1',
45+
port: common.PORT,
46+
path: '/',
47+
method: 'GET',
48+
rejectUnauthorized: false
49+
};
50+
51+
var req = https.request(requestOptions, function(res) {
52+
res.on('data', function(d) {});
53+
setImmediate(shutdown);
54+
});
55+
req.end();
56+
});

0 commit comments

Comments
 (0)