11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst http = require('http');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst server = http.createServer((req, res) => res.end());
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
91cb0ef41Sopenharmony_citmpdir.refresh();
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciserver.listen(common.PIPE, common.mustCall(() =>
121cb0ef41Sopenharmony_ci  asyncLoop(makeKeepAliveRequest, 10, common.mustCall(() =>
131cb0ef41Sopenharmony_ci    server.getConnections(common.mustSucceed((conns) => {
141cb0ef41Sopenharmony_ci      assert.strictEqual(conns, 1);
151cb0ef41Sopenharmony_ci      server.close();
161cb0ef41Sopenharmony_ci    }))
171cb0ef41Sopenharmony_ci  ))
181cb0ef41Sopenharmony_ci));
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cifunction asyncLoop(fn, times, cb) {
211cb0ef41Sopenharmony_ci  fn(function handler() {
221cb0ef41Sopenharmony_ci    if (--times) {
231cb0ef41Sopenharmony_ci      fn(handler);
241cb0ef41Sopenharmony_ci    } else {
251cb0ef41Sopenharmony_ci      cb();
261cb0ef41Sopenharmony_ci    }
271cb0ef41Sopenharmony_ci  });
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_cifunction makeKeepAliveRequest(cb) {
311cb0ef41Sopenharmony_ci  http.get({
321cb0ef41Sopenharmony_ci    socketPath: common.PIPE,
331cb0ef41Sopenharmony_ci    headers: { connection: 'keep-alive' }
341cb0ef41Sopenharmony_ci  }, (res) => res.on('data', common.mustNotCall())
351cb0ef41Sopenharmony_ci    .on('error', assert.fail)
361cb0ef41Sopenharmony_ci    .on('end', cb)
371cb0ef41Sopenharmony_ci  );
381cb0ef41Sopenharmony_ci}
39