summaryrefslogtreecommitdiff
path: root/test/internet/test-http-dns-fail.js
blob: 94f2487173c266eb1fc1dc5866f8195feb3219f5 (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
'use strict';
/*
 * Repeated requests for a domain that fails to resolve
 * should trigger the error event after each attempt.
 */

const common = require('../common');
const assert = require('assert');
const http = require('http');

function httpreq(count) {
  if (count > 1) return;

  const req = http.request({
    host: 'not-a-real-domain-name.nobody-would-register-this-as-a-tld',
    port: 80,
    path: '/',
    method: 'GET'
  }, common.mustNotCall());

  req.on('error', common.mustCall((e) => {
    assert.strictEqual(e.code, 'ENOTFOUND');
    httpreq(count + 1);
  }));

  req.end();
}

httpreq(0);