• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.mustSucceed((conns) => {
14      assert.strictEqual(conns, 1);
15      server.close();
16    }))
17  ))
18));
19
20function asyncLoop(fn, times, cb) {
21  fn(function handler() {
22    if (--times) {
23      fn(handler);
24    } else {
25      cb();
26    }
27  });
28}
29
30function makeKeepAliveRequest(cb) {
31  http.get({
32    socketPath: common.PIPE,
33    headers: { connection: 'keep-alive' }
34  }, (res) => res.on('data', common.mustNotCall())
35    .on('error', assert.fail)
36    .on('end', cb)
37  );
38}
39