summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-client-incomingmessage-destroy.js
blob: 64b95dc2ff273fa8e561a755e14f3f1142f59bbb (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
'use strict';

const common = require('../common');
const { createServer, get } = require('http');
const assert = require('assert');

const server = createServer(common.mustCall((req, res) => {
  res.writeHead(200);
  res.write('Part of res.');
}));

function onUncaught(error) {
  assert.strictEqual(error.message, 'Destroy test');
  server.close();
}

process.on('uncaughtException', common.mustCall(onUncaught));

server.listen(0, () => {
  get({
    port: server.address().port
  }, common.mustCall((res) => {
    const err = new Error('Destroy test');
    assert.strictEqual(res.errored, null);
    res.destroy(err);
    assert.strictEqual(res.closed, false);
    assert.strictEqual(res.errored, err);
    res.on('close', () => {
      assert.strictEqual(res.closed, true);
    });
  }));
});