Skip to content

Commit

Permalink
test: cover dgram handle send failures
Browse files Browse the repository at this point in the history
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 28, 2017
1 parent 70cdfc5 commit 597aff0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/parallel/test-dgram-send-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.