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: https://github.com/nodejs/node/pull/13158
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
cjihrig 2017-05-22 13:56:31 -04:00
parent 413691fde0
commit 06757cd0dc

View File

@ -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);
}));
}