mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 11:36:57 +00:00

Many tests use assert.fail(null, null, msg) where it would be simpler to use common.fail(msg). This is largely because common.fail() is fairly new. This commit makes the replacement when applicable. PR-URL: https://github.com/nodejs/node/pull/7735 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
38 lines
990 B
JavaScript
38 lines
990 B
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var mustCall = common.mustCall;
|
|
var assert = require('assert');
|
|
var dgram = require('dgram');
|
|
var dns = require('dns');
|
|
|
|
var socket = dgram.createSocket('udp4');
|
|
var buffer = Buffer.from('gary busey');
|
|
|
|
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) {
|
|
common.fail('Error should not be emitted if there is callback');
|
|
}
|
|
|
|
function onError(err) {
|
|
assert.ok(err);
|
|
socket.close();
|
|
}
|