diff --git a/packages/core/test/acceptance/misc/ws.test.js b/packages/core/test/acceptance/misc/ws.test.js index 7b086923f3..67600b4eff 100644 --- a/packages/core/test/acceptance/misc/ws.test.js +++ b/packages/core/test/acceptance/misc/ws.test.js @@ -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(() => { diff --git a/packages/core/test/quarantine/ws/scripts/subprotocols.json b/packages/core/test/acceptance/ws/scripts/subprotocols.json similarity index 100% rename from packages/core/test/quarantine/ws/scripts/subprotocols.json rename to packages/core/test/acceptance/ws/scripts/subprotocols.json diff --git a/packages/core/test/quarantine/ws/test_options.js b/packages/core/test/acceptance/ws/ws-subprotocols.test.js similarity index 64% rename from packages/core/test/quarantine/ws/test_options.js rename to packages/core/test/acceptance/ws/ws-subprotocols.test.js index 7c650dbeef..57cf202990 100644 --- a/packages/core/test/quarantine/ws/test_options.js +++ b/packages/core/test/acceptance/ws/ws-subprotocols.test.js @@ -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'); @@ -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(); }); }); diff --git a/packages/core/test/quarantine/test_config_plugin_package.js b/packages/core/test/quarantine/test_config_plugin_package.js index 936e428fc4..16d357d33a 100644 --- a/packages/core/test/quarantine/test_config_plugin_package.js +++ b/packages/core/test/quarantine/test_config_plugin_package.js @@ -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(); }); diff --git a/packages/core/test/quarantine/test_environments.js b/packages/core/test/quarantine/test_environments.js index 283101ffae..9e952a2976 100644 --- a/packages/core/test/quarantine/test_environments.js +++ b/packages/core/test/quarantine/test_environments.js @@ -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(); diff --git a/packages/core/test/targets/simple_tls.js b/packages/core/test/targets/simple_tls.js index cee67b684d..bd43515f99 100644 --- a/packages/core/test/targets/simple_tls.js +++ b/packages/core/test/targets/simple_tls.js @@ -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; diff --git a/packages/core/test/targets/simple_ws.js b/packages/core/test/targets/simple_ws.js index fe600e26ff..800ebfc344 100644 --- a/packages/core/test/targets/simple_ws.js +++ b/packages/core/test/targets/simple_ws.js @@ -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; diff --git a/packages/core/test/targets/ws_tls.js b/packages/core/test/targets/ws_tls.js index 3eacf85851..222e3e9526 100644 --- a/packages/core/test/targets/ws_tls.js +++ b/packages/core/test/targets/ws_tls.js @@ -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;