xref: /third_party/node/test/parallel/test-net-socket-connect-without-cb.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// This test ensures that socket.connect can be called without callback
51cb0ef41Sopenharmony_ci// which is optional.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst net = require('net');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst server = net.createServer(common.mustCall(function(conn) {
101cb0ef41Sopenharmony_ci  conn.end();
111cb0ef41Sopenharmony_ci  server.close();
121cb0ef41Sopenharmony_ci})).listen(0, common.mustCall(function() {
131cb0ef41Sopenharmony_ci  const client = new net.Socket();
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  client.on('connect', common.mustCall(function() {
161cb0ef41Sopenharmony_ci    client.end();
171cb0ef41Sopenharmony_ci  }));
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  const address = server.address();
201cb0ef41Sopenharmony_ci  if (!common.hasIPv6 && address.family === 'IPv6') {
211cb0ef41Sopenharmony_ci    // Necessary to pass CI running inside containers.
221cb0ef41Sopenharmony_ci    client.connect(address.port);
231cb0ef41Sopenharmony_ci  } else {
241cb0ef41Sopenharmony_ci    client.connect(address);
251cb0ef41Sopenharmony_ci  }
261cb0ef41Sopenharmony_ci}));
27

Indexes created Thu Nov 07 10:32:03 CST 2024