Skip to content

Commit 29a29f7

Browse files
James HerringtonBridgeAR
James Herrington
authored andcommitted
test: add tests for Socket.setNoDelay
PR-URL: #24250 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent d6f91ba commit 29a29f7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
7+
const truthyValues = [true, 1, 'true', {}, []];
8+
const falseyValues = [false, 0, ''];
9+
const genSetNoDelay = (desiredArg) => (enable) => {
10+
assert.strictEqual(enable, desiredArg);
11+
};
12+
13+
// setNoDelay should default to true
14+
let socket = new net.Socket({
15+
handle: {
16+
setNoDelay: common.mustCall(genSetNoDelay(true))
17+
}
18+
});
19+
socket.setNoDelay();
20+
21+
socket = new net.Socket({
22+
handle: {
23+
setNoDelay: common.mustCall(genSetNoDelay(true), truthyValues.length)
24+
}
25+
});
26+
truthyValues.forEach((testVal) => socket.setNoDelay(testVal));
27+
28+
socket = new net.Socket({
29+
handle: {
30+
setNoDelay: common.mustCall(genSetNoDelay(false), falseyValues.length)
31+
}
32+
});
33+
falseyValues.forEach((testVal) => socket.setNoDelay(testVal));
34+
35+
// if a handler doesn't have a setNoDelay function it shouldn't be called.
36+
// In the case below, if it is called an exception will be thrown
37+
socket = new net.Socket({
38+
handle: {
39+
setNoDelay: null
40+
}
41+
});
42+
const returned = socket.setNoDelay(true);
43+
assert.ok(returned instanceof net.Socket);

0 commit comments

Comments
 (0)