0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-process-getactivehandles.js
gwer 0142276977
test: replace indexOf with includes
Start the transition to Array.prototype.includes() and
String.prototype.includes().  This commit refactors most of the
comparisons of Array.prototype.indexOf() and String.prototype.indexOf()
return values with -1 to the former methods in tests.

PR-URL: https://github.com/nodejs/node/pull/12604
Refs: https://github.com/nodejs/node/issues/12586
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-04-30 04:08:46 +03:00

48 lines
921 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const net = require('net');
const NUM = 8;
const connections = [];
const clients = [];
let clients_counter = 0;
const server = net.createServer(function listener(c) {
connections.push(c);
}).listen(0, makeConnection);
function makeConnection() {
if (clients_counter >= NUM) return;
net.connect(server.address().port, function connected() {
clientConnected(this);
makeConnection();
});
}
function clientConnected(client) {
clients.push(client);
if (++clients_counter >= NUM)
checkAll();
}
function checkAll() {
const handles = process._getActiveHandles();
clients.forEach(function(item) {
assert.ok(handles.includes(item));
item.destroy();
});
connections.forEach(function(item) {
assert.ok(handles.includes(item));
item.end();
});
assert.ok(handles.includes(server));
server.close();
}