1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const http = require('http'); 5 6const server = http.createServer((req, res) => res.end()); 7 8const tmpdir = require('../common/tmpdir'); 9tmpdir.refresh(); 10 11server.listen(common.PIPE, common.mustCall(() => 12 asyncLoop(makeKeepAliveRequest, 10, common.mustCall(() => 13 server.getConnections(common.mustCall((err, conns) => { 14 assert.ifError(err); 15 assert.strictEqual(conns, 1); 16 server.close(); 17 })) 18 )) 19)); 20 21function asyncLoop(fn, times, cb) { 22 fn(function handler() { 23 if (--times) { 24 fn(handler); 25 } else { 26 cb(); 27 } 28 }); 29} 30 31function makeKeepAliveRequest(cb) { 32 http.get({ 33 socketPath: common.PIPE, 34 headers: { connection: 'keep-alive' } 35 }, (res) => res.on('data', common.mustNotCall()) 36 .on('error', assert.fail) 37 .on('end', cb) 38 ); 39} 40