Skip to content
Permalink
Browse files

test: cover dgram handle send failures

This commit adds test coverage for the case where a dgram socket
successfully binds, but the handle's send() function fails.

PR-URL: #13158
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information...
cjihrig authored and jasnell committed May 22, 2017
1 parent 70cdfc5 commit 597aff0846af7c7310283b4bc0ea6c59fe49ea06
Showing with 29 additions and 0 deletions.
  1. +29 −0 test/parallel/test-dgram-send-error.js
@@ -35,3 +35,32 @@ getSocket((socket) => {

socket.send('foo', socket.address().port, 'localhost', callback);
});

{
const socket = dgram.createSocket('udp4');

socket.on('message', common.mustNotCall('Should not receive any messages.'));

socket.bind(common.mustCall(() => {
const port = socket.address().port;
const errCode = process.binding('uv').UV_UNKNOWN;
const callback = common.mustCall((err) => {
socket.close();
assert.strictEqual(err.code, 'UNKNOWN');
assert.strictEqual(err.errno, 'UNKNOWN');
assert.strictEqual(err.syscall, 'send');
assert.strictEqual(err.address, common.localhostIPv4);
assert.strictEqual(err.port, port);
assert.strictEqual(
err.message,
`${err.syscall} ${err.code} ${err.address}:${err.port}`
);
});

socket._handle.send = function() {
return errCode;
};

socket.send('foo', port, common.localhostIPv4, callback);
}));
}

0 comments on commit 597aff0

Please sign in to comment.
You can’t perform that action at this time.