Skip to content

Commit

Permalink
test: refactor pummel/test-net-many-clients
Browse files Browse the repository at this point in the history
* Use port 0 instead of `common.PORT`.
* Reduce `concurrent` from 100 to 50 and `connections_per_client` from 5
  to 3. This is to avoid side effects from other tests. Prior to this
  change, running this along with test-keep-alive would result in
  failures on my local setup, apparently due to network throttling.
* Remove unnecessary `console.log()` and improve remaining
  `console.log()` to provide clearer information.

PR-URL: #25485
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Trott authored and BethGriggs committed May 10, 2019
1 parent 3d13787 commit d5d085c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions test/pummel/test-net-many-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,29 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const net = require('net');

// settings
const bytes = 1024 * 40;
const concurrency = 100;
const connections_per_client = 5;
const concurrency = 50;
const connections_per_client = 3;

// measured
let total_connections = 0;

const body = 'C'.repeat(bytes);

const server = net.createServer(function(c) {
console.log('connected');
total_connections++;
console.log('#');
console.log('connected', total_connections);
c.write(body);
c.end();
});

function runClient(callback) {
const client = net.createConnection(common.PORT);
function runClient(port, callback) {
const client = net.createConnection(port);

client.connections = 0;

Expand Down Expand Up @@ -79,17 +78,17 @@ function runClient(callback) {
assert.ok(!client.fd);

if (this.connections < connections_per_client) {
this.connect(common.PORT);
this.connect(port);
} else {
callback();
}
});
}

server.listen(common.PORT, function() {
server.listen(0, function() {
let finished_clients = 0;
for (let i = 0; i < concurrency; i++) {
runClient(function() {
runClient(server.address().port, function() {
if (++finished_clients === concurrency) server.close();
});
}
Expand Down

0 comments on commit d5d085c

Please sign in to comment.