• 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    readStart() {}
18  }
19});
20socket.setNoDelay();
21
22socket = new net.Socket({
23  handle: {
24    setNoDelay: common.mustCall(genSetNoDelay(true), 1),
25    readStart() {}
26  }
27});
28truthyValues.forEach((testVal) => socket.setNoDelay(testVal));
29
30socket = new net.Socket({
31  handle: {
32    setNoDelay: common.mustNotCall(),
33    readStart() {}
34  }
35});
36falseyValues.forEach((testVal) => socket.setNoDelay(testVal));
37
38socket = new net.Socket({
39  handle: {
40    setNoDelay: common.mustCall(() => {}, 3),
41    readStart() {}
42  }
43});
44truthyValues.concat(falseyValues).concat(truthyValues)
45  .forEach((testVal) => socket.setNoDelay(testVal));
46
47// If a handler doesn't have a setNoDelay function it shouldn't be called.
48// In the case below, if it is called an exception will be thrown
49socket = new net.Socket({
50  handle: {
51    setNoDelay: null,
52    readStart() {}
53  }
54});
55const returned = socket.setNoDelay(true);
56assert.ok(returned instanceof net.Socket);
57