summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-client-agent-end-close-event.js
blob: ce202f4d2f283c2209d4897dff1e541bb23448e9 (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
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

const server = http.createServer(common.mustCall((req, res) => {
  res.end('hello');
}));

const keepAliveAgent = new http.Agent({ keepAlive: true });

server.listen(0, common.mustCall(() => {
  const req = http.get({
    port: server.address().port,
    agent: keepAliveAgent
  });

  req
    .on('response', common.mustCall((res) => {
      res
        .on('close', common.mustCall(() => {
          assert.strictEqual(req.destroyed, true);
          server.close();
          keepAliveAgent.destroy();
        }))
        .on('data', common.mustCall());
    }))
    .end();
}));