From 597aff0846af7c7310283b4bc0ea6c59fe49ea06 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 22 May 2017 13:56:31 -0400 Subject: [PATCH] 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 Reviewed-By: Luigi Pinca --- test/parallel/test-dgram-send-error.js | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/parallel/test-dgram-send-error.js b/test/parallel/test-dgram-send-error.js index 3cec72cca0718d..73b4584cc3bc82 100644 --- a/test/parallel/test-dgram-send-error.js +++ b/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); + })); +}