node/test/parallel/test-http-agent-close.js
Robert Nagy 027e1c706d http: ensure client request emits close
If socket creation failed then an error would be
emitted on the client request object, but not
'close' nor would destroyed be set to true.

PR-URL: https://github.com/nodejs/node/pull/33178
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2020-05-04 11:35:58 +02:00

22 lines
467 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const agent = new http.Agent();
const _err = new Error('kaboom');
agent.createSocket = function(req, options, cb) {
cb(_err);
};
const req = http
.request({
agent
})
.on('error', common.mustCall((err) => {
assert.strictEqual(err, _err);
}))
.on('close', common.mustCall(() => {
assert.strictEqual(req.destroyed, true);
}));