Permalink
Browse files

test: add coverage for dgram send() errors

This commit adds code coverage for emitted and callback errors
for dgram's Socket#send() method.

PR-URL: #11248
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information...
cjihrig committed Feb 8, 2017
1 parent 90ab68b commit b32ae9e74dab25b905ef001638af7df77ca2d987
Showing with 37 additions and 0 deletions.
  1. +37 −0 test/parallel/test-dgram-send-error.js
@@ -0,0 +1,37 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const mockError = new Error('mock DNS error');
function getSocket(callback) {
const socket = dgram.createSocket('udp4');
socket.on('message', common.mustNotCall('Should not receive any messages.'));
socket.bind(common.mustCall(() => {
socket._handle.lookup = function(address, callback) {
process.nextTick(callback, mockError);
};
callback(socket);
}));
return socket;
}
getSocket((socket) => {
socket.on('error', common.mustCall((err) => {
socket.close();
assert.strictEqual(err, mockError);
}));
socket.send('foo', socket.address().port, 'localhost');
});
getSocket((socket) => {
const callback = common.mustCall((err) => {
socket.close();
assert.strictEqual(err, mockError);
});
socket.send('foo', socket.address().port, 'localhost', callback);
});

0 comments on commit b32ae9e

Please sign in to comment.