Skip to content

Commit

Permalink
test: add test for net-socket-setTimeout callback
Browse files Browse the repository at this point in the history
PR-URL: #25084
Refs: #19060
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
ZYSzys authored and addaleax committed Jan 27, 2019
1 parent 802ea05 commit 22a9fe3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/parallel/test-net-socket-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const nonNumericDelays = [
];
const badRangeDelays = [-0.001, -1, -Infinity, Infinity, NaN];
const validDelays = [0, 0.001, 1, 1e6];
const invalidCallbacks = [
1, '100', true, false, null, {}, [], Symbol('test')
];


for (let i = 0; i < nonNumericDelays.length; i++) {
Expand All @@ -49,6 +52,19 @@ for (let i = 0; i < validDelays.length; i++) {
s.setTimeout(validDelays[i], () => {});
}

for (let i = 0; i < invalidCallbacks.length; i++) {
[0, 1].forEach((mesc) =>
common.expectsError(
() => s.setTimeout(mesc, invalidCallbacks[i]),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError,
message: 'Callback must be a function'
}
)
);
}

const server = net.Server();
server.listen(0, common.mustCall(() => {
const socket = net.createConnection(server.address().port);
Expand Down

0 comments on commit 22a9fe3

Please sign in to comment.