2015-05-26 09:17:00 +02:00
|
|
|
'use strict';
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
2017-01-08 14:19:00 +01:00
|
|
|
const mustCall = common.mustCall;
|
2016-12-31 00:38:06 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const dgram = require('dgram');
|
|
|
|
const dns = require('dns');
|
2015-05-26 09:17:00 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const socket = dgram.createSocket('udp4');
|
|
|
|
const buffer = Buffer.from('gary busey');
|
2015-05-26 09:17:00 +02:00
|
|
|
|
|
|
|
dns.setServers([]);
|
|
|
|
|
|
|
|
socket.once('error', onEvent);
|
|
|
|
|
|
|
|
// assert that:
|
|
|
|
// * callbacks act as "error" listeners if given.
|
|
|
|
// * error is never emitter for missing dns entries
|
|
|
|
// if a callback that handles error is present
|
|
|
|
// * error is emitted if a callback with no argument is passed
|
|
|
|
socket.send(buffer, 0, buffer.length, 100,
|
|
|
|
'dne.example.com', mustCall(callbackOnly));
|
|
|
|
|
|
|
|
function callbackOnly(err) {
|
|
|
|
assert.ok(err);
|
|
|
|
socket.removeListener('error', onEvent);
|
|
|
|
socket.on('error', mustCall(onError));
|
|
|
|
socket.send(buffer, 0, buffer.length, 100, 'dne.example.com');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEvent(err) {
|
2017-04-09 19:53:30 +02:00
|
|
|
assert.fail('Error should not be emitted if there is callback');
|
2015-05-26 09:17:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onError(err) {
|
|
|
|
assert.ok(err);
|
|
|
|
socket.close();
|
|
|
|
}
|