node/test/parallel/test-net-socket-setnodelay.js
Rich Trott 6059cbedbd
test: remove unnecessary noop function args to mustCall()
PR-URL: https://github.com/nodejs/node/pull/45027
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-10-18 12:13:41 +00:00

57 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const truthyValues = [true, 1, 'true', {}, []];
const falseyValues = [false, 0, ''];
const genSetNoDelay = (desiredArg) => (enable) => {
assert.strictEqual(enable, desiredArg);
};
// setNoDelay should default to true
let socket = new net.Socket({
handle: {
setNoDelay: common.mustCall(genSetNoDelay(true)),
readStart() {}
}
});
socket.setNoDelay();
socket = new net.Socket({
handle: {
setNoDelay: common.mustCall(genSetNoDelay(true), 1),
readStart() {}
}
});
truthyValues.forEach((testVal) => socket.setNoDelay(testVal));
socket = new net.Socket({
handle: {
setNoDelay: common.mustNotCall(),
readStart() {}
}
});
falseyValues.forEach((testVal) => socket.setNoDelay(testVal));
socket = new net.Socket({
handle: {
setNoDelay: common.mustCall(3),
readStart() {}
}
});
truthyValues.concat(falseyValues).concat(truthyValues)
.forEach((testVal) => socket.setNoDelay(testVal));
// If a handler doesn't have a setNoDelay function it shouldn't be called.
// In the case below, if it is called an exception will be thrown
socket = new net.Socket({
handle: {
setNoDelay: null,
readStart() {}
}
});
const returned = socket.setNoDelay(true);
assert.ok(returned instanceof net.Socket);