summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-dns-error.js
blob: a016c9883e0067c9be1b78787ca57a21148eb5c7 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var common = require('../common');
var assert = require('assert');

var http = require('http');
var https = require('https');

var expected_bad_requests = 0;
var actual_bad_requests = 0;

var host = '********';
host += host;
host += host;
host += host;
host += host;
host += host;

function do_not_call() {
  throw new Error('This function should not have been called.');
}

function test(mod) {
  expected_bad_requests += 2;

  // Bad host name should not throw an uncatchable exception.
  // Ensure that there is time to attach an error listener.
  var req = mod.get({host: host, port: 42}, do_not_call);
  req.on('error', function(err) {
    assert.equal(err.code, 'ENOTFOUND');
    actual_bad_requests++;
  });
  // http.get() called req.end() for us

  var req = mod.request({method: 'GET', host: host, port: 42}, do_not_call);
  req.on('error', function(err) {
    assert.equal(err.code, 'ENOTFOUND');
    actual_bad_requests++;
  });
  req.end();
}

test(https);
test(http);

process.on('exit', function() {
  assert.equal(actual_bad_requests, expected_bad_requests);
});