summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-client-agent-abort-close-event.js
blob: 437d2aad222780ea7f6cc07f2b7f50afc85f684a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';
const common = require('../common');
const http = require('http');

const server = http.createServer(common.mustNotCall());

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

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

  req
    .on('socket', common.mustNotCall())
    .on('response', common.mustNotCall())
    .on('close', common.mustCall(() => {
      server.close();
      keepAliveAgent.destroy();
    }))
    .abort();
}));