11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst http = require('http');
51cb0ef41Sopenharmony_ciconst net = require('net');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst agent = new http.Agent({
81cb0ef41Sopenharmony_ci  keepAlive: true,
91cb0ef41Sopenharmony_ci});
101cb0ef41Sopenharmony_ciconst socket = new net.Socket();
111cb0ef41Sopenharmony_ci// If _handle exists then internals assume a couple methods exist.
121cb0ef41Sopenharmony_cisocket._handle = {
131cb0ef41Sopenharmony_ci  ref() { },
141cb0ef41Sopenharmony_ci  readStart() { },
151cb0ef41Sopenharmony_ci};
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall((req, res) => {
181cb0ef41Sopenharmony_ci  res.end();
191cb0ef41Sopenharmony_ci})).listen(0, common.mustCall(() => {
201cb0ef41Sopenharmony_ci  const req = new http.ClientRequest(`http://localhost:${server.address().port}/`);
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  // Manually add the socket without a _handle.
231cb0ef41Sopenharmony_ci  agent.freeSockets[agent.getName(req)] = [socket];
241cb0ef41Sopenharmony_ci  // Now force the agent to use the socket and check that _handle exists before
251cb0ef41Sopenharmony_ci  // calling asyncReset().
261cb0ef41Sopenharmony_ci  agent.addRequest(req, {});
271cb0ef41Sopenharmony_ci  req.on('response', common.mustCall(() => {
281cb0ef41Sopenharmony_ci    server.close();
291cb0ef41Sopenharmony_ci  }));
301cb0ef41Sopenharmony_ci  req.end();
311cb0ef41Sopenharmony_ci}));
32