• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const net = require('net');
6
7const truthyValues = [true, 1, 'true', {}, []];
8const falseyValues = [false, 0, ''];
9const genSetNoDelay = (desiredArg) => (enable) => {
10  assert.strictEqual(enable, desiredArg);
11};
12
13// setNoDelay should default to true
14let socket = new net.Socket({
15  handle: {
16    setNoDelay: common.mustCall(genSetNoDelay(true))
17  }
18});
19socket.setNoDelay();
20
21socket = new net.Socket({
22  handle: {
23    setNoDelay: common.mustCall(genSetNoDelay(true), 1)
24  }
25});
26truthyValues.forEach((testVal) => socket.setNoDelay(testVal));
27
28socket = new net.Socket({
29  handle: {
30    setNoDelay: common.mustNotCall()
31  }
32});
33falseyValues.forEach((testVal) => socket.setNoDelay(testVal));
34
35socket = new net.Socket({
36  handle: {
37    setNoDelay: common.mustCall(() => {}, 3)
38  }
39});
40truthyValues.concat(falseyValues).concat(truthyValues)
41  .forEach((testVal) => socket.setNoDelay(testVal));
42
43// If a handler doesn't have a setNoDelay function it shouldn't be called.
44// In the case below, if it is called an exception will be thrown
45socket = new net.Socket({
46  handle: {
47    setNoDelay: null
48  }
49});
50const returned = socket.setNoDelay(true);
51assert.ok(returned instanceof net.Socket);
52