summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-client-res-destroyed.js
blob: 188ab06c155731f8842754b845f18b84a5676b68 (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
32
33
34
35
36
37
38
39
40
41
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');

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

  server.listen(0, common.mustCall(() => {
    http.get({
      port: server.address().port
    }, common.mustCall((res) => {
      assert.strictEqual(res.destroyed, false);
      res.destroy();
      assert.strictEqual(res.destroyed, true);
      res.on('close', common.mustCall(() => {
        server.close();
      }));
    }));
  }));
}

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

  server.listen(0, common.mustCall(() => {
    http.get({
      port: server.address().port
    }, common.mustCall((res) => {
      assert.strictEqual(res.destroyed, false);
      res.on('close', common.mustCall(() => {
        assert.strictEqual(res.destroyed, true);
        server.close();
      })).resume();
    }));
  }));
}