Skip to content

Commit

Permalink
test(core): fix ws subprotocols quarantined tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobridge committed Apr 4, 2024
1 parent e9f5413 commit 8c1817b
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 56 deletions.
6 changes: 3 additions & 3 deletions packages/core/test/acceptance/misc/ws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const createTestServer = require('../../targets/simple_ws');
let server;
let port;
beforeEach(async () => {
server = createTestServer().listen(0, function () {
port = server.address().port;
});
const serverInfo = await createTestServer();
port = serverInfo.port;
server = serverInfo.server;
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,76 @@
'use strict';

const { test } = require('tap');
const { test, beforeEach, afterEach } = require('tap');
const core = require('../../..');
const vuserLauncher = core.runner.runner;
const { SSMS } = require('../../../lib/ssms');
const createTestServer = require('../../targets/simple_ws');

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

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

//simple-ws
test('Subprotocols - using a known subprotocol', function (t) {
const script = require('./scripts/subprotocols.json');
vuserLauncher(script).then((sessions) => {
sessions.on('done', (nr) => {
script.config.target = `ws://127.0.0.1:${port}`;
vuserLauncher(script).then((ee) => {
ee.on('done', (nr) => {
const report = SSMS.legacyReport(nr).report();
console.log(report);
t.equal(
Object.keys(report.errors).length,
0,
'Test with a subprotocol should complete with no errors'
);
sessions.stop().then(() => {
ee.stop().then(() => {
t.end();
});
});

sessions.run();
ee.run();
});
});

//simple-ws
test('Subprotocols - no subprotocol', function (t) {
const script = require('./scripts/subprotocols.json');

script.config.target = `ws://127.0.0.1:${port}`;
delete script.config.ws;

vuserLauncher(script).then((sessions) => {
sessions.on('done', (nr) => {
vuserLauncher(script).then((ee) => {
ee.on('done', (nr) => {
const report = SSMS.legacyReport(nr).report();
t.equal(
Object.keys(report.errors).length,
0,
'Test with no subprotocol set should complete with no errors'
);
sessions.stop().then(() => {
ee.stop().then(() => {
t.end();
});
});

sessions.run();
ee.run();
});
});

test('Subprotocols - unknown subprotocol', function (t) {
const script = require('./scripts/subprotocols.json');
script.config.target = `ws://127.0.0.1:${port}`;

script.config.ws = {
subprotocols: ['unsupportedByTheServer']
};

vuserLauncher(script).then((sessions) => {
sessions.on('done', (nr) => {
vuserLauncher(script).then((ee) => {
ee.on('done', (nr) => {
const report = SSMS.legacyReport(nr).report();
t.equal(Object.keys(report.errors).length, 1, 'Should have one error');

Expand All @@ -67,11 +81,11 @@ test('Subprotocols - unknown subprotocol', function (t) {
'The error should be of "no subprotocol" type'
);

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

sessions.run();
ee.run();
});
});
2 changes: 2 additions & 0 deletions packages/core/test/quarantine/test_config_plugin_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ test('Normal artillery-plugin-*', function (t) {

function runTest(t, scriptName) {
const script = require(scriptName);
console.log(script);
runner(script).then(function (ee) {
ee.on('plugin_loaded', function (stats) {
console.log('hey');
t.ok(true);
t.end();
});
Expand Down
91 changes: 57 additions & 34 deletions packages/core/test/quarantine/test_environments.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,70 @@
'use strict';

var { test } = require('tap');
var runner = require('../../lib/runner').runner;
var createTarget = require('./lib/interfakify').create;
var url = require('url');
const { test, beforeEach, afterEach } = require('tap');
const runner = require('../../lib/runner').runner;
// const createTarget = require('./lib/interfakify').create;
const { updateGlobalObject } = require('../../index');
const { SSMS } = require('../../lib/ssms');
const url = require('url');
const createTestServer = require('../targets/simple');

test('environments - override target', function (t) {
var script = require('../scripts/hello_environments.json');
runner(script, null, { environment: 'production' }).then(function (ee) {
ee.on('done', function (report) {
t.ok(
report.requestsCompleted === 0,
'there should be no completed requests'
);
t.ok(
report.errors.ETIMEDOUT && report.errors.ETIMEDOUT > 1,
'there should ETIMEDOUT errors'
);
t.end();
});
ee.run();
});
let server;
let port;
beforeEach(async () => {
await updateGlobalObject();
server = await createTestServer(0);
port = server.info.port;
});

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

// test('environments - override target', function (t) {
// const script = require('../scripts/hello_environments.json');
// runner(script, null, { environment: 'production' }).then(function (ee) {
// ee.on('done', function (nr) {
// const report = SSMS.legacyReport(nr).report();
// console.log(report)
// t.ok(
// report.requestsCompleted === 0,
// 'there should be no completed requests'
// );
// t.ok(
// report.errors.ETIMEDOUT && report.errors.ETIMEDOUT > 1,
// 'there should ETIMEDOUT errors'
// );
// ee.stop().then(() => {
// t.end();
// });
// });
// ee.run();
// });
// });

test('environments - override target and phases', function (t) {
var startedAt;
var script = require('../scripts/hello_environments.json');
var target = createTarget(
script.scenarios[0].flow,
script.config.environments.staging
);
target.listen(
url.parse(script.config.environments.staging.target).port || 80
);
let startedAt;
const script = require('../scripts/hello_environments.json');
script.config.environments.staging.target = `http://127.0.0.1:${port}`;
// var target = createTarget(
// script.scenarios[0].flow,
// script.config.environments.staging
// );
// target.listen(
// url.parse(script.config.environments.staging.target).port || 80
// );
runner(script, null, { environment: 'staging' }).then(function (ee) {
ee.on('done', function (report) {
var completedAt = process.hrtime(startedAt);
var delta = (completedAt[0] * 1e9 + completedAt[1]) / 1e6;
ee.on('done', function (nr) {
const report = SSMS.legacyReport(nr).report();
console.log(report);
const completedAt = process.hrtime(startedAt);
const delta = (completedAt[0] * 1e9 + completedAt[1]) / 1e6;

t.ok(report.codes[200], 'stats should not be empty');
t.ok(delta >= 20 * 1000, "should've run for 20 seconds");
target.stop();
t.end();
ee.stop().then(() => {
t.end();
});
});
startedAt = process.hrtime();
ee.run();
Expand Down
6 changes: 5 additions & 1 deletion packages/core/test/targets/simple_tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ const createTestServer = () => {
res.end('hello\n');
});

return server;
return new Promise((resolve, reject) => {
server.listen(0, function () {
resolve({ server, port: server.address().port });
});
});
};

module.exports = createTestServer;
6 changes: 5 additions & 1 deletion packages/core/test/targets/simple_ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ const createTestServer = (port, host = '127.0.0.1') => {
}
}

return server;
return new Promise((resolve, reject) => {
server.listen(0, function () {
resolve({ server, wss, port: server.address().port });
});
});
};

module.exports = createTestServer;
6 changes: 5 additions & 1 deletion packages/core/test/targets/ws_tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const createTestServer = (port = 9443) => {
});
});

return app;
return new Promise((resolve, reject) => {
app.listen(0, function () {
resolve({ server: app, wss, port: app.address().port });
});
});
};

module.exports = createTestServer;

0 comments on commit 8c1817b

Please sign in to comment.