• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const net = require('net');
4
5// This file tests the option handling of net.connect,
6// net.createConnect, and new Socket().connect
7
8const tmpdir = require('../common/tmpdir');
9tmpdir.refresh();
10
11const CLIENT_VARIANTS = 12;
12
13// Test connect(path)
14{
15  const prefix = `${common.PIPE}-net-connect-options-path`;
16  const serverPath = `${prefix}-server`;
17  let counter = 0;
18  const server = net.createServer()
19  .on('connection', common.mustCall(function(socket) {
20    socket.end('ok');
21  }, CLIENT_VARIANTS))
22  .listen(serverPath, common.mustCall(function() {
23    const getConnectCb = () => common.mustCall(function() {
24      this.end();
25      this.on('close', common.mustCall(function() {
26        counter++;
27        if (counter === CLIENT_VARIANTS) {
28          server.close();
29        }
30      }));
31    });
32
33    // CLIENT_VARIANTS depends on the following code
34    net.connect(serverPath, getConnectCb()).resume();
35    net.connect(serverPath)
36      .on('connect', getConnectCb())
37      .resume();
38    net.createConnection(serverPath, getConnectCb()).resume();
39    net.createConnection(serverPath)
40      .on('connect', getConnectCb())
41      .resume();
42    new net.Socket().connect(serverPath, getConnectCb()).resume();
43    new net.Socket().connect(serverPath)
44      .on('connect', getConnectCb())
45      .resume();
46    net.connect({ path: serverPath }, getConnectCb()).resume();
47    net.connect({ path: serverPath })
48      .on('connect', getConnectCb())
49      .resume();
50    net.createConnection({ path: serverPath }, getConnectCb()).resume();
51    net.createConnection({ path: serverPath })
52      .on('connect', getConnectCb())
53      .resume();
54    new net.Socket().connect({ path: serverPath }, getConnectCb()).resume();
55    new net.Socket().connect({ path: serverPath })
56      .on('connect', getConnectCb())
57      .resume();
58  }));
59}
60