Skip to content

Commit 307da2d

Browse files
Trottaddaleax
authored andcommitted
test: refactor pummel/test-net-many-clients
* 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>
1 parent 69c0841 commit 307da2d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

test/pummel/test-net-many-clients.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,29 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
const common = require('../common');
23+
require('../common');
2424
const assert = require('assert');
2525
const net = require('net');
2626

2727
// settings
2828
const bytes = 1024 * 40;
29-
const concurrency = 100;
30-
const connections_per_client = 5;
29+
const concurrency = 50;
30+
const connections_per_client = 3;
3131

3232
// measured
3333
let total_connections = 0;
3434

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

3737
const server = net.createServer(function(c) {
38-
console.log('connected');
3938
total_connections++;
40-
console.log('#');
39+
console.log('connected', total_connections);
4140
c.write(body);
4241
c.end();
4342
});
4443

45-
function runClient(callback) {
46-
const client = net.createConnection(common.PORT);
44+
function runClient(port, callback) {
45+
const client = net.createConnection(port);
4746

4847
client.connections = 0;
4948

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

8180
if (this.connections < connections_per_client) {
82-
this.connect(common.PORT);
81+
this.connect(port);
8382
} else {
8483
callback();
8584
}
8685
});
8786
}
8887

89-
server.listen(common.PORT, function() {
88+
server.listen(0, function() {
9089
let finished_clients = 0;
9190
for (let i = 0; i < concurrency; i++) {
92-
runClient(function() {
91+
runClient(server.address().port, function() {
9392
if (++finished_clients === concurrency) server.close();
9493
});
9594
}

0 commit comments

Comments
 (0)