Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor pummel tests #25485

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions test/pummel/test-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

// This test requires the program 'wrk'
// This test requires the program 'wrk'.
const common = require('../common');
if (common.isWindows)
common.skip('no `wrk` on windows');
Expand All @@ -47,9 +47,9 @@ let normalReqSec = 0;

const runAb = (opts, callback) => {
const args = [
'-c', opts.concurrent || 100,
'-c', opts.concurrent || 50,
'-t', opts.threads || 2,
'-d', opts.duration || '10s',
'-d', opts.duration || '5s',
];

if (!opts.keepalive) {
Expand All @@ -58,7 +58,7 @@ const runAb = (opts, callback) => {
}

args.push(url.format({ hostname: '127.0.0.1',
port: common.PORT, protocol: 'http' }));
port: opts.port, protocol: 'http' }));

const child = spawn('wrk', args);
child.stderr.pipe(process.stderr);
Expand Down Expand Up @@ -90,11 +90,12 @@ const runAb = (opts, callback) => {
});
};

server.listen(common.PORT, () => {
runAb({ keepalive: true }, (reqSec) => {
server.listen(0, () => {
const port = server.address().port;
runAb({ keepalive: true, port: port }, (reqSec) => {
keepAliveReqSec = reqSec;

runAb({ keepalive: false }, (reqSec) => {
runAb({ keepalive: false, port: port }, (reqSec) => {
normalReqSec = reqSec;
server.close();
});
Expand Down
6 changes: 3 additions & 3 deletions test/pummel/test-net-connect-econnrefused.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
// verify that connect reqs are properly cleaned up
// Verify that connect reqs are properly cleaned up.

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

const ROUNDS = 10;
const ATTEMPTS_PER_ROUND = 100;
const ROUNDS = 5;
const ATTEMPTS_PER_ROUND = 50;
let rounds = 1;
let reqs = 0;

Expand Down
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
16 changes: 8 additions & 8 deletions test/pummel/test-net-pingpong.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const net = require('net');

let tests_run = 0;

function pingPongTest(port, host, on_complete) {
function pingPongTest(host, on_complete) {
const N = 1000;
let count = 0;
let sent_final_ping = false;
Expand Down Expand Up @@ -69,8 +69,8 @@ function pingPongTest(port, host, on_complete) {
});
});

server.listen(port, host, function() {
const client = net.createConnection(port, host);
server.listen(0, host, function() {
const client = net.createConnection(server.address().port, host);

client.setEncoding('utf8');

Expand Down Expand Up @@ -110,12 +110,12 @@ function pingPongTest(port, host, on_complete) {
});
}

/* All are run at once, so run on different ports */
pingPongTest(common.PORT, 'localhost');
pingPongTest(common.PORT + 1, null);
// All are run at once and will run on different ports.
pingPongTest('localhost');
pingPongTest(null);

// This IPv6 isn't working on Solaris
if (!common.isSunOS) pingPongTest(common.PORT + 2, '::1');
// This IPv6 isn't working on Solaris.
if (!common.isSunOS) pingPongTest('::1');

process.on('exit', function() {
assert.strictEqual(tests_run, common.isSunOS ? 2 : 3);
Expand Down