2017-05-25 00:32:04 -07:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
|
|
|
|
|
|
|
const server = http.createServer((req, res) => res.end());
|
|
|
|
|
2017-12-24 22:38:11 -08:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
2017-05-25 00:32:04 -07:00
|
|
|
|
|
|
|
server.listen(common.PIPE, common.mustCall(() =>
|
|
|
|
asyncLoop(makeKeepAliveRequest, 10, common.mustCall(() =>
|
2020-09-06 22:27:07 +02:00
|
|
|
server.getConnections(common.mustSucceed((conns) => {
|
2017-05-25 00:32:04 -07:00
|
|
|
assert.strictEqual(conns, 1);
|
|
|
|
server.close();
|
|
|
|
}))
|
|
|
|
))
|
|
|
|
));
|
|
|
|
|
|
|
|
function asyncLoop(fn, times, cb) {
|
|
|
|
fn(function handler() {
|
|
|
|
if (--times) {
|
2022-06-21 14:50:55 +02:00
|
|
|
setTimeout(() => fn(handler), common.platformTimeout(10));
|
2017-05-25 00:32:04 -07:00
|
|
|
} else {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-11-27 22:56:21 -08:00
|
|
|
|
2017-05-25 00:32:04 -07:00
|
|
|
function makeKeepAliveRequest(cb) {
|
|
|
|
http.get({
|
|
|
|
socketPath: common.PIPE,
|
|
|
|
headers: { connection: 'keep-alive' }
|
|
|
|
}, (res) => res.on('data', common.mustNotCall())
|
|
|
|
.on('error', assert.fail)
|
|
|
|
.on('end', cb)
|
|
|
|
);
|
|
|
|
}
|