summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-agent-uninitialized.js
blob: dbb38e3b0f98471c98d61ff7824840050eb316a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';

const common = require('../common');
const http = require('http');
const net = require('net');

const agent = new http.Agent({
  keepAlive: true,
});
const socket = new net.Socket();

const server = http.createServer(common.mustCall((req, res) => {
  res.end();
})).listen(0, common.mustCall(() => {
  const req = new http.ClientRequest(`http://localhost:${server.address().port}/`);

  // Manually add the socket without a _handle.
  agent.freeSockets[agent.getName(req)] = [socket];
  // Now force the agent to use the socket and check that _handle exists before
  // calling asyncReset().
  agent.addRequest(req, {});
  req.on('response', common.mustCall(() => {
    server.close();
  }));
  req.end();
}));