11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst net = require('net'); 61cb0ef41Sopenharmony_ciconst NUM = 8; 71cb0ef41Sopenharmony_ciconst connections = []; 81cb0ef41Sopenharmony_ciconst clients = []; 91cb0ef41Sopenharmony_cilet clients_counter = 0; 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst server = net.createServer(function listener(c) { 121cb0ef41Sopenharmony_ci connections.push(c); 131cb0ef41Sopenharmony_ci}).listen(0, makeConnection); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cifunction makeConnection() { 171cb0ef41Sopenharmony_ci if (clients_counter >= NUM) return; 181cb0ef41Sopenharmony_ci net.connect(server.address().port, function connected() { 191cb0ef41Sopenharmony_ci clientConnected(this); 201cb0ef41Sopenharmony_ci makeConnection(); 211cb0ef41Sopenharmony_ci }); 221cb0ef41Sopenharmony_ci} 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_cifunction clientConnected(client) { 261cb0ef41Sopenharmony_ci clients.push(client); 271cb0ef41Sopenharmony_ci if (++clients_counter >= NUM) 281cb0ef41Sopenharmony_ci checkAll(); 291cb0ef41Sopenharmony_ci} 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_cifunction checkAll() { 331cb0ef41Sopenharmony_ci const handles = process._getActiveHandles(); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci clients.forEach(function(item) { 361cb0ef41Sopenharmony_ci assert.ok(handles.includes(item)); 371cb0ef41Sopenharmony_ci item.destroy(); 381cb0ef41Sopenharmony_ci }); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci connections.forEach(function(item) { 411cb0ef41Sopenharmony_ci assert.ok(handles.includes(item)); 421cb0ef41Sopenharmony_ci item.end(); 431cb0ef41Sopenharmony_ci }); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci assert.ok(handles.includes(server)); 461cb0ef41Sopenharmony_ci server.close(); 471cb0ef41Sopenharmony_ci} 48