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

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

const server = createServer(common.mustCall((req, res) => {
  req.destroy(new Error('Destroy test'));
}));

function onUncaught(error) {}

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

server.listen(0, common.mustCall(() => {
  get({
    port: server.address().port
  }, (res) => {
    res.resume();
  }).on('error', (error) => {
    assert.strictEqual(error.message, 'socket hang up');
    assert.strictEqual(error.code, 'ECONNRESET');
    server.close();
  });
}));