Skip to content

Commit

Permalink
test(core): fix some quarantine tests (#2627)
Browse files Browse the repository at this point in the history
* test(core): fix config variables quarantined test

* test(core): fix tls quarantined test

* test(core): fix ws tls quarantined test

* test(core): removed file

* test(core): fix ws subprotocols quarantined tests
  • Loading branch information
bernardobridge authored Apr 5, 2024
1 parent 9dfd766 commit d55b152
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 209 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
'use strict';

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

test('config variables', function (t) {
let server;
let port;
beforeEach(async () => {
server = await createTestServer(0);
port = server.info.port;
});

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

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

runner(script).then(function (ee) {
ee.on('done', function (nr) {
const report = SSMS.legacyReport(nr).report();
t.ok(report.codes[200] > 0, 'there are 200s for /');
t.ok(report.codes[404] > 0, 'there are 404s for /will/404');
t.end();
ee.stop().then(() => {
t.end();
});
});

ee.run();
});
});
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
59 changes: 59 additions & 0 deletions packages/core/test/acceptance/tls.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const { test, beforeEach, afterEach } = require('tap');
const runner = require('../../lib/runner').runner;
const { updateGlobalObject } = require('../../index');
const { SSMS } = require('../../lib/ssms');
const createTestServer = require('../targets/simple_tls');

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

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

test('tls strict', function (t) {
const script = require('../scripts/tls-strict.json');
script.config.target = `https://127.0.0.1:${port}`;
runner(script).then(function (ee) {
ee.on('done', function (nr) {
const report = SSMS.legacyReport(nr).report();
console.log(report);
const rejected = report.errors.DEPTH_ZERO_SELF_SIGNED_CERT;
t.ok(rejected, 'requests to self-signed tls certs fail by default');

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

test('tls lax', function (t) {
const script = require('../scripts/tls-lax.json');
script.config.target = `https://127.0.0.1:${port}`;
runner(script).then(function (ee) {
ee.on('done', function (nr) {
const report = SSMS.legacyReport(nr).report();
const rejected = report.errors.DEPTH_ZERO_SELF_SIGNED_CERT;
const reason =
'requests to self-signed tls certs pass ' +
'when `rejectUnauthorized` is false';

t.ok(rejected == null, reason);

ee.stop().then(() => {
t.end();
});
});
ee.run();
});
});
91 changes: 91 additions & 0 deletions packages/core/test/acceptance/ws/ws-subprotocols.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use strict';

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();
});

test('Subprotocols - using a known subprotocol', function (t) {
const script = require('./scripts/subprotocols.json');
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'
);
ee.stop().then(() => {
t.end();
});
});

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

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((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'
);
ee.stop().then(() => {
t.end();
});
});

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((ee) => {
ee.on('done', (nr) => {
const report = SSMS.legacyReport(nr).report();
t.equal(Object.keys(report.errors).length, 1, 'Should have one error');

// FIXME: This test is coupled to the error message generated by the ws library
t.ok(
Object.keys(report.errors)[0].toLowerCase().indexOf('no subprotocol') >
-1,
'The error should be of "no subprotocol" type'
);

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

ee.run();
});
});
56 changes: 56 additions & 0 deletions packages/core/test/acceptance/ws/ws-tls.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

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

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

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

test('TLS - with rejectUnauthorized false', function (t) {
const script = require('./scripts/ws-tls.json');
script.config.target = `wss://127.0.0.1:${port}`;
vuserLauncher(script).then(function (ee) {
ee.on('done', function (nr) {
const report = SSMS.legacyReport(nr).report();
console.log(report);
t.ok(Object.keys(report.errors).length === 0, 'Test ran without errors');
ee.stop().then(() => {
t.end();
});
});
ee.run();
});
});

test('TLS - with rejectUnauthorized true', function (t) {
const script = require('./scripts/ws-tls.json');
script.config.target = `wss://127.0.0.1:${port}`;
script.config.ws.rejectUnauthorized = true;
vuserLauncher(script).then(function (ee) {
ee.on('done', function (nr) {
const report = SSMS.legacyReport(nr).report();
console.log(report);
t.equal(
Object.keys(report.errors).length,
1,
`Test should run with one error. Got: ${Object.keys(report.errors)}`
);
ee.stop().then(() => {
t.end();
});
});
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
Loading

0 comments on commit d55b152

Please sign in to comment.