0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/internet/test-dgram-send-cb-quelches-error.js
Rich Trott 06c29a66d4 test: remove common.fail()
common.fail() was added to paste over issues with assert.fail() function
signature. assert.fail() has been updated to accept a single argument so
common.fail() is no longer necessary.

PR-URL: https://github.com/nodejs/node/pull/12293
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-04-12 14:25:33 -07:00

38 lines
1004 B
JavaScript

'use strict';
const common = require('../common');
const mustCall = common.mustCall;
const assert = require('assert');
const dgram = require('dgram');
const dns = require('dns');
const socket = dgram.createSocket('udp4');
const 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) {
assert.fail('Error should not be emitted if there is callback');
}
function onError(err) {
assert.ok(err);
socket.close();
}