• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3require('../common');
4const assert = require('assert');
5const net = require('net');
6const NUM = 8;
7const connections = [];
8const clients = [];
9let clients_counter = 0;
10
11const server = net.createServer(function listener(c) {
12  connections.push(c);
13}).listen(0, makeConnection);
14
15
16function makeConnection() {
17  if (clients_counter >= NUM) return;
18  net.connect(server.address().port, function connected() {
19    clientConnected(this);
20    makeConnection();
21  });
22}
23
24
25function clientConnected(client) {
26  clients.push(client);
27  if (++clients_counter >= NUM)
28    checkAll();
29}
30
31
32function checkAll() {
33  const handles = process._getActiveHandles();
34
35  clients.forEach(function(item) {
36    assert.ok(handles.includes(item));
37    item.destroy();
38  });
39
40  connections.forEach(function(item) {
41    assert.ok(handles.includes(item));
42    item.end();
43  });
44
45  assert.ok(handles.includes(server));
46  server.close();
47}
48