11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst http = require('http');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cilet socketsCreated = 0;
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciclass Agent extends http.Agent {
91cb0ef41Sopenharmony_ci  createConnection(options, oncreate) {
101cb0ef41Sopenharmony_ci    const socket = super.createConnection(options, oncreate);
111cb0ef41Sopenharmony_ci    socketsCreated++;
121cb0ef41Sopenharmony_ci    return socket;
131cb0ef41Sopenharmony_ci  }
141cb0ef41Sopenharmony_ci}
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst server = http.createServer((req, res) => res.end());
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
191cb0ef41Sopenharmony_ci  const port = server.address().port;
201cb0ef41Sopenharmony_ci  const agent = new Agent({
211cb0ef41Sopenharmony_ci    keepAlive: true,
221cb0ef41Sopenharmony_ci    maxSockets: 1
231cb0ef41Sopenharmony_ci  });
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  const req = http.get({ agent, port }, common.mustCall((res) => {
261cb0ef41Sopenharmony_ci    res.resume();
271cb0ef41Sopenharmony_ci    res.on('end', () => {
281cb0ef41Sopenharmony_ci      res.destroy();
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci      http.get({ agent, port }, common.mustCall((res) => {
311cb0ef41Sopenharmony_ci        res.resume();
321cb0ef41Sopenharmony_ci        assert.strictEqual(socketsCreated, 1);
331cb0ef41Sopenharmony_ci        agent.destroy();
341cb0ef41Sopenharmony_ci        server.close();
351cb0ef41Sopenharmony_ci      }));
361cb0ef41Sopenharmony_ci    });
371cb0ef41Sopenharmony_ci  }));
381cb0ef41Sopenharmony_ci  req.end();
391cb0ef41Sopenharmony_ci}));
40