Skip to content

Commit 597aff0

Browse files
cjihrigjasnell
authored andcommitted
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 70cdfc5 commit 597aff0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/parallel/test-dgram-send-error.js

+29
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,32 @@ getSocket((socket) => {
3535

3636
socket.send('foo', socket.address().port, 'localhost', callback);
3737
});
38+
39+
{
40+
const socket = dgram.createSocket('udp4');
41+
42+
socket.on('message', common.mustNotCall('Should not receive any messages.'));
43+
44+
socket.bind(common.mustCall(() => {
45+
const port = socket.address().port;
46+
const errCode = process.binding('uv').UV_UNKNOWN;
47+
const callback = common.mustCall((err) => {
48+
socket.close();
49+
assert.strictEqual(err.code, 'UNKNOWN');
50+
assert.strictEqual(err.errno, 'UNKNOWN');
51+
assert.strictEqual(err.syscall, 'send');
52+
assert.strictEqual(err.address, common.localhostIPv4);
53+
assert.strictEqual(err.port, port);
54+
assert.strictEqual(
55+
err.message,
56+
`${err.syscall} ${err.code} ${err.address}:${err.port}`
57+
);
58+
});
59+
60+
socket._handle.send = function() {
61+
return errCode;
62+
};
63+
64+
socket.send('foo', port, common.localhostIPv4, callback);
65+
}));
66+
}

0 commit comments

Comments
 (0)