Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
squash: add test for recv/send buffer sizes
  • Loading branch information
danbev committed Sep 20, 2017
commit 517886867406245136c506acce7a070fbeb6873b
22 changes: 22 additions & 0 deletions test/parallel/test-dgram-socket-buffer-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,25 @@ const dgram = require('dgram');
socket.close();
}));
}

function checkBufferSizeError(type, size) {
const errorObj = {
code: 'ERR_SOCKET_BUFFER_SIZE',
type: Error,
message: new RegExp('^Could not get or set buffer' +
' size: Error: EINVAL: invalid argument,' +
' uv_' + type + '_buffer_size$')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I believe a string (instead of a regex) is enough to get exact matching here. You might want to use a template string instead of concatenation, I think we agreed on that preference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually used a template for this but the linter complained which is why I changed it. I'll take another look though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use templates, except if the line becomes too long, in that case you can concatenate templates and string literals:

'Could not get or set buffer size: Error: EINVAL: ' +
`invalid argument, uv_${type}_buffer_size`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated now.

};
const functionName = 'set' + type.charAt(0).toUpperCase() +
type.slice(1) + 'BufferSize';
const socket = dgram.createSocket('udp4');
socket.bind(common.mustCall(() => {
assert.throws(() => {
socket[functionName](size);
}, common.expectsError(errorObj));
socket.close();
}));
}

checkBufferSizeError('recv', 2147483648);
checkBufferSizeError('send', 2147483648);