node/test/parallel/test-http-client-req-error-dont-double-fire.js
Joyee Cheung 0fb1e07689
test: mock the lookup function in parallel tests
These tests should not make any DNS calls. The lookup would fail
when the DNS requests are hijacked and time out instead of erroring
out.

PR-URL: https://github.com/nodejs/node/pull/17296
Refs: https://github.com/nodejs/help/issues/687
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-11-28 23:06:56 +08:00

26 lines
677 B
JavaScript

'use strict';
// This tests that the error emitted on the socket does
// not get fired again when the 'error' event handler throws
// an error.
const assert = require('assert');
const http = require('http');
const common = require('../common');
const { addresses } = require('../common/internet');
const { errorLookupMock } = require('../common/dns');
const host = addresses.INVALID_HOST;
const req = http.get({
host,
lookup: common.mustCall(errorLookupMock())
});
const err = new Error('mock unexpected code error');
req.on('error', common.mustCall(() => {
throw err;
}));
process.on('uncaughtException', common.mustCall((e) => {
assert.strictEqual(e, err);
}));