11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst net = require('net');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// This file tests the option handling of net.connect,
61cb0ef41Sopenharmony_ci// net.createConnect, and new Socket().connect
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
91cb0ef41Sopenharmony_citmpdir.refresh();
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst CLIENT_VARIANTS = 12;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci// Test connect(path)
141cb0ef41Sopenharmony_ci{
151cb0ef41Sopenharmony_ci  const prefix = `${common.PIPE}-net-connect-options-path`;
161cb0ef41Sopenharmony_ci  const serverPath = `${prefix}-server`;
171cb0ef41Sopenharmony_ci  let counter = 0;
181cb0ef41Sopenharmony_ci  const server = net.createServer()
191cb0ef41Sopenharmony_ci  .on('connection', common.mustCall(function(socket) {
201cb0ef41Sopenharmony_ci    socket.end('ok');
211cb0ef41Sopenharmony_ci  }, CLIENT_VARIANTS))
221cb0ef41Sopenharmony_ci  .listen(serverPath, common.mustCall(function() {
231cb0ef41Sopenharmony_ci    const getConnectCb = () => common.mustCall(function() {
241cb0ef41Sopenharmony_ci      this.end();
251cb0ef41Sopenharmony_ci      this.on('close', common.mustCall(function() {
261cb0ef41Sopenharmony_ci        counter++;
271cb0ef41Sopenharmony_ci        if (counter === CLIENT_VARIANTS) {
281cb0ef41Sopenharmony_ci          server.close();
291cb0ef41Sopenharmony_ci        }
301cb0ef41Sopenharmony_ci      }));
311cb0ef41Sopenharmony_ci    });
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci    // CLIENT_VARIANTS depends on the following code
341cb0ef41Sopenharmony_ci    net.connect(serverPath, getConnectCb()).resume();
351cb0ef41Sopenharmony_ci    net.connect(serverPath)
361cb0ef41Sopenharmony_ci      .on('connect', getConnectCb())
371cb0ef41Sopenharmony_ci      .resume();
381cb0ef41Sopenharmony_ci    net.createConnection(serverPath, getConnectCb()).resume();
391cb0ef41Sopenharmony_ci    net.createConnection(serverPath)
401cb0ef41Sopenharmony_ci      .on('connect', getConnectCb())
411cb0ef41Sopenharmony_ci      .resume();
421cb0ef41Sopenharmony_ci    new net.Socket().connect(serverPath, getConnectCb()).resume();
431cb0ef41Sopenharmony_ci    new net.Socket().connect(serverPath)
441cb0ef41Sopenharmony_ci      .on('connect', getConnectCb())
451cb0ef41Sopenharmony_ci      .resume();
461cb0ef41Sopenharmony_ci    net.connect({ path: serverPath }, getConnectCb()).resume();
471cb0ef41Sopenharmony_ci    net.connect({ path: serverPath })
481cb0ef41Sopenharmony_ci      .on('connect', getConnectCb())
491cb0ef41Sopenharmony_ci      .resume();
501cb0ef41Sopenharmony_ci    net.createConnection({ path: serverPath }, getConnectCb()).resume();
511cb0ef41Sopenharmony_ci    net.createConnection({ path: serverPath })
521cb0ef41Sopenharmony_ci      .on('connect', getConnectCb())
531cb0ef41Sopenharmony_ci      .resume();
541cb0ef41Sopenharmony_ci    new net.Socket().connect({ path: serverPath }, getConnectCb()).resume();
551cb0ef41Sopenharmony_ci    new net.Socket().connect({ path: serverPath })
561cb0ef41Sopenharmony_ci      .on('connect', getConnectCb())
571cb0ef41Sopenharmony_ci      .resume();
581cb0ef41Sopenharmony_ci  }));
591cb0ef41Sopenharmony_ci}
60