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(core): parallelise core test suite #2622

Merged
merged 15 commits into from
Apr 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"lint-fix": "npm run lint -- --fix",
"test": "npm run test:unit && npm run test:acceptance",
"test:unit": "tap --no-coverage --color --timeout=300 test/core/unit/*.test.js",
"test:acceptance": "bash test/core/run.sh"
"test:acceptance": "tap --no-coverage --color --timeout 300 test/core/test_* && tap --no-coverage --color --timeout=300 test/core/acceptance/**/*.test.js"
},
"devDependencies": {
"@hapi/basic": "^6.0.0",
Expand Down
68 changes: 68 additions & 0 deletions packages/core/test/core/acceptance/misc/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const l = require('lodash');
const runner = require('../../../..').runner.runner;
const { SSMS } = require('../../../../lib/ssms');

const runGenericRunnerTest = (script, t) => {
const startedAt = process.hrtime();
let completedPhases = 0;

runner(script).then(function (ee) {
ee.on('phaseStarted', function (x) {
t.ok(x, 'phaseStarted event emitted');
});
ee.on('phaseCompleted', function (x) {
completedPhases++;
t.ok(x, 'phaseCompleted event emitted');
});
ee.on('stats', function (stats) {
t.ok(stats, 'intermediate stats event emitted');
});
ee.on('done', function (nr) {
const report = SSMS.legacyReport(nr).report();
const requests = report.requestsCompleted;
const scenarios = report.scenariosCompleted;
console.log('# requests = %s, scenarios = %s', requests, scenarios);

t.equal(
completedPhases,
script.config.phases.length,
'Should have completed all phases'
);
const completedAt = process.hrtime(startedAt);
const delta = (completedAt[0] * 1e9 + completedAt[1]) / 1e6;
const minDuration = l.reduce(
script.config.phases,
function (acc, phaseSpec) {
return acc + phaseSpec.duration * 1000;
},
0
);
t.ok(
delta >= minDuration,
'Should run for at least the total duration of phases'
);

t.ok(requests > 0, 'Should have successful requests');
t.ok(scenarios > 0, 'Should have successful scenarios');

if (report.errors) {
console.log(`# errors: ${JSON.stringify(report.errors, null, 4)}`);
}
t.equal(
Object.keys(report.errors).length,
0,
'Should have no errors in report'
);

ee.stop().then(() => {
t.end();
});
});

ee.run();
});
};

module.exports = {
runGenericRunnerTest
};
21 changes: 21 additions & 0 deletions packages/core/test/core/acceptance/misc/http.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { test, beforeEach, afterEach } = require('tap');
const { runGenericRunnerTest } = require('./helper');
const createTestServer = require('../../targets/simple');

let server;
let port;
beforeEach(async () => {
server = await createTestServer(0);
port = server.info.port;
});

afterEach(() => {
server.stop();
});

test('generic http test works', (t) => {
const script = require('../../scripts/hello.json');
script.config.target = `http://127.0.0.1:${port}`;

runGenericRunnerTest(script, t);
});
21 changes: 21 additions & 0 deletions packages/core/test/core/acceptance/misc/large-payload.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { test, beforeEach, afterEach } = require('tap');
const { runGenericRunnerTest } = require('./helper');
const createTestServer = require('../../targets/simple');

let server;
let port;
beforeEach(async () => {
server = await createTestServer(0);
port = server.info.port;
});

afterEach(() => {
server.stop();
});

test('generic http test works', (t) => {
const script = require('../../scripts/large_payload.json');
script.config.target = `http://127.0.0.1:${port}`;

runGenericRunnerTest(script, t);
});
21 changes: 21 additions & 0 deletions packages/core/test/core/acceptance/misc/multiple-phases.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { test, beforeEach, afterEach } = require('tap');
const { runGenericRunnerTest } = require('./helper');
const createTestServer = require('../../targets/simple');

let server;
let port;
beforeEach(async () => {
server = await createTestServer(0);
port = server.info.port;
});

afterEach(() => {
server.stop();
});

test('generic http test works', (t) => {
const script = require('../../scripts/multiple_phases.json');
script.config.target = `http://127.0.0.1:${port}`;

runGenericRunnerTest(script, t);
});
22 changes: 22 additions & 0 deletions packages/core/test/core/acceptance/misc/socketio-with-args.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { test, beforeEach, afterEach } = require('tap');
const { runGenericRunnerTest } = require('./helper');
const createTestServer = require('../../targets/socketio_args');

let server;
let port;
beforeEach(async () => {
server = createTestServer().listen(0, function () {
port = server.address().port;
});
});

afterEach(() => {
server.close();
});

test('socketio with args works', (t) => {
const script = require('../../scripts/hello_socketio_with_args.json');
script.config.target = `http://127.0.0.1:${port}`;

runGenericRunnerTest(script, t);
});
22 changes: 22 additions & 0 deletions packages/core/test/core/acceptance/misc/socketio-with-http.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { test, beforeEach, afterEach } = require('tap');
const { runGenericRunnerTest } = require('./helper');
const createTestServer = require('../../targets/express_socketio');

let server;
let port;
beforeEach(async () => {
server = createTestServer().listen(0, function () {
port = server.address().port;
});
});

afterEach(() => {
server.close();
});

test('socketio with http works', (t) => {
const script = require('../../scripts/express_socketio.json');
script.config.target = `http://127.0.0.1:${port}`;

runGenericRunnerTest(script, t);
});
22 changes: 22 additions & 0 deletions packages/core/test/core/acceptance/misc/socketio.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { test, beforeEach, afterEach } = require('tap');
const { runGenericRunnerTest } = require('./helper');
const createTestServer = require('../../targets/simple_socketio');

let server;
let port;
beforeEach(async () => {
const serverInfo = await createTestServer();
server = serverInfo.server;
port = serverInfo.port;
});

afterEach(() => {
server.close();
});

test('generic socketio test works', (t) => {
const script = require('../../scripts/hello_socketio.json');
script.config.target = `http://127.0.0.1:${port}`;

runGenericRunnerTest(script, t);
});
31 changes: 31 additions & 0 deletions packages/core/test/core/acceptance/misc/ws-proxy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { test, beforeEach, afterEach } = require('tap');
const { runGenericRunnerTest } = require('./helper');
const createTestServers = require('../../targets/ws_proxy');

let server;
let proxyServer;
let port;
let proxyPort;

beforeEach(async () => {
const servers = createTestServers();
server = servers.wsServer.listen(0, function () {
port = this.address().port;
proxyServer = servers.proxyServer.listen(0, function () {
proxyPort = this.address().port;
});
});
});

afterEach(() => {
server.close();
proxyServer.close();
});

test('generic ws test works', (t) => {
const script = require('../../scripts/ws_proxy.json');
script.config.target = `ws://127.0.0.1:${port}`;
script.config.ws.proxy.url = `http://127.0.0.1:${proxyPort}`;

runGenericRunnerTest(script, t);
});
22 changes: 22 additions & 0 deletions packages/core/test/core/acceptance/misc/ws.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { test, beforeEach, afterEach } = require('tap');
const { runGenericRunnerTest } = require('./helper');
const createTestServer = require('../../targets/simple_ws');

let server;
let port;
beforeEach(async () => {
server = createTestServer().listen(0, function () {
port = server.address().port;
});
});

afterEach(() => {
server.close();
});

test('generic ws test works', (t) => {
const script = require('../../scripts/hello_ws.json');
script.config.target = `ws://127.0.0.1:${port}`;

runGenericRunnerTest(script, t);
});
21 changes: 0 additions & 21 deletions packages/core/test/core/index.js

This file was deleted.

37 changes: 0 additions & 37 deletions packages/core/test/core/run.sh

This file was deleted.

Loading
Loading