• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const mustCall = common.mustCall;
4const assert = require('assert');
5const dgram = require('dgram');
6const dns = require('dns');
7
8const socket = dgram.createSocket('udp4');
9const buffer = Buffer.from('gary busey');
10
11dns.setServers([]);
12
13socket.once('error', onEvent);
14
15// assert that:
16// * callbacks act as "error" listeners if given.
17// * error is never emitter for missing dns entries
18//   if a callback that handles error is present
19// * error is emitted if a callback with no argument is passed
20socket.send(buffer, 0, buffer.length, 100,
21            'dne.example.com', mustCall(callbackOnly));
22
23function callbackOnly(err) {
24  assert.ok(err);
25  socket.removeListener('error', onEvent);
26  socket.on('error', mustCall(onError));
27  socket.send(buffer, 0, buffer.length, 100, 'dne.invalid');
28}
29
30function onEvent(err) {
31  assert.fail(`Error should not be emitted if there is callback: ${err}`);
32}
33
34function onError(err) {
35  assert.ok(err);
36  socket.close();
37}
38