node/test/parallel/test-http-client-res-destroyed.js
Robert Nagy 28e6626ce7
http: set IncomingMessage.destroyed
IncomingMessage is a Readable stream and should properly
set the destroyed property.

PR-URL: https://github.com/nodejs/node/pull/33131
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2020-05-09 07:57:45 +02:00

42 lines
983 B
JavaScript

'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();
}));
}));
}