summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-agent-uninitialized-with-handle.js
blob: 77f01771734c87410ecbb6eecf97d35d564ea9f7 (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
27
28
29
30
31
'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();
// If _handle exists then internals assume a couple methods exist.
socket._handle = {
  ref() { },
  readStart() { },
};

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();
}));