forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-dgram-send-cb-quelches-error.js
More file actions
37 lines (30 loc) · 998 Bytes
/
test-dgram-send-cb-quelches-error.js
File metadata and controls
37 lines (30 loc) · 998 Bytes
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
'use strict';
const common = require('../common');
var mustCall = common.mustCall;
const assert = require('assert');
const dgram = require('dgram');
const 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();
}