From 7a3e2536f9aa8d2c024c9db23179a10ff4409760 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Wed, 29 Nov 2023 20:09:07 +0000 Subject: [PATCH 01/12] Add K6 own get_load method --- bzt/modules/k6.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/bzt/modules/k6.py b/bzt/modules/k6.py index 4bc496f36..2ed59ed25 100644 --- a/bzt/modules/k6.py +++ b/bzt/modules/k6.py @@ -17,7 +17,7 @@ from bzt.modules import ScenarioExecutor from bzt.modules.console import ExecutorWidget from bzt.modules.aggregator import ResultsReader, ConsolidatingAggregator -from bzt.utils import RequiredTool, CALL_PROBLEMS, FileReader, shutdown_process +from bzt.utils import RequiredTool, CALL_PROBLEMS, FileReader, shutdown_process, dehumanize_time, numeric_types class K6Executor(ScenarioExecutor): @@ -67,6 +67,55 @@ def startup(self): cmdline += [self.script] self.process = self._execute(cmdline) + def get_load(self): + def eval_int(value): + try: + return int(value) + except (ValueError, TypeError): + return value + + def eval_float(value): + try: + return int(value) + except (ValueError, TypeError): + return value + + raw_load = self.get_raw_load() + + iterations = eval_int(raw_load.iterations or 0) + ramp_up = raw_load.ramp_up + + throughput = eval_float(raw_load.throughput or 0) + concurrency = eval_int(raw_load.concurrency or 0) + + steps = eval_int(raw_load.steps) + hold = dehumanize_time(raw_load.hold or 0) + + if ramp_up is None: + duration = hold + else: + ramp_up = dehumanize_time(raw_load.ramp_up) + duration = hold + ramp_up + + msg = '' + if not isinstance(concurrency, numeric_types + (type(None),)): + msg += "Invalid concurrency value[%s]: %s " % (type(concurrency).__name__, concurrency) + if not isinstance(throughput, numeric_types + (type(None),)): + msg += "Invalid throughput value[%s]: %s " % (type(throughput).__name__, throughput) + if not isinstance(steps, numeric_types + (type(None),)): + msg += "Invalid throughput value[%s]: %s " % (type(steps).__name__, steps) + if not isinstance(iterations, numeric_types + (type(None),)): + msg += "Invalid throughput value[%s]: %s " % (type(iterations).__name__, iterations) + + if msg: + raise TaurusConfigError(msg) + + return self.LOAD_FMT(concurrency=concurrency, ramp_up=ramp_up, throughput=throughput, hold=hold, + iterations=iterations, duration=duration, steps=steps) + + + + def get_widget(self): if not self.widget: label = "%s" % self From 9d8904b4a83107c5ade6b9e43d400e1cec149137 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Mon, 8 Jan 2024 16:08:38 +0000 Subject: [PATCH 02/12] add vscode to gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6c6514ab8..b9b4637f8 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,7 @@ bzt/resources/NUnitRunner/* integr-artifacts* *.log examples/local* -bzt/20* \ No newline at end of file +bzt/20* + +# vscode +.vscode \ No newline at end of file From 0ca4a2cef8e092b829815f3b135300b63a4ba4f6 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Mon, 8 Jan 2024 16:14:06 +0000 Subject: [PATCH 03/12] added change file --- site/dat/docs/changes/Fix-k6-scenario-within-k6-test.change | 1 + 1 file changed, 1 insertion(+) create mode 100644 site/dat/docs/changes/Fix-k6-scenario-within-k6-test.change diff --git a/site/dat/docs/changes/Fix-k6-scenario-within-k6-test.change b/site/dat/docs/changes/Fix-k6-scenario-within-k6-test.change new file mode 100644 index 000000000..8ddbc0614 --- /dev/null +++ b/site/dat/docs/changes/Fix-k6-scenario-within-k6-test.change @@ -0,0 +1 @@ +Added own get_load method to k6.py so iterations is defaulted to 0 if not specified in the Taurus scenario. \ No newline at end of file From 8334e75637c537e79c4322ce00f38216fe7bbb6b Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Tue, 30 Jan 2024 15:20:10 +0000 Subject: [PATCH 04/12] add tests --- tests/unit/modules/test_k6.py | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/unit/modules/test_k6.py b/tests/unit/modules/test_k6.py index 2c5dff8df..744aee8c8 100644 --- a/tests/unit/modules/test_k6.py +++ b/tests/unit/modules/test_k6.py @@ -1,6 +1,7 @@ from os.path import join import bzt +from bzt.engine.names import EXEC from bzt.modules.aggregator import DataPoint, KPISet from bzt.modules.k6 import K6Executor, K6LogReader @@ -103,6 +104,59 @@ def test_iterations_multiplied(self): }) self.assertIn("--iterations 100", self.CMD_LINE) + def test_get_load(self): + self.configure({EXEC: { + "ramp-up": "1", "concurrency": "2", "throughput": "3"}}) + self.assertEqual(self.obj.execution.get("ramp-up"), "1") + self.assertEqual(self.obj.execution.get("concurrency"), "2") + self.assertEqual(self.obj.execution.get("throughput"), "3") + load = self.obj.get_load() + self.assertEqual(load.ramp_up, 1) + self.assertEqual(load.concurrency, 2) + self.assertEqual(load.throughput, 3) + self.assertEqual(load.iterations, 0) + + self.assertEqual(self.obj.execution.get("ramp-up"), "1") + self.assertEqual(self.obj.execution.get("concurrency"), {"local": "2"}) + self.assertEqual(self.obj.execution.get("throughput"), {"local": "3"}) + + self.obj.engine.config.get("execution")[0]["concurrency"] = "22" + load = self.obj.get_load() + self.assertEqual(load.concurrency, 22) + self.assertEqual(self.obj.execution.get("concurrency"), {"local": "22"}) + + def test_get_load_defaults(self): + self.configure({EXEC: {}}) + self.assertFalse(self.obj.execution.get("ramp-up")) + self.assertFalse(self.obj.execution.get("concurrency")) + self.assertFalse(self.obj.execution.get("throughput")) + self.assertFalse(self.obj.execution.get("iterations")) + load = self.obj.get_load() + self.assertEqual(load.ramp_up, None) + self.assertEqual(load.concurrency, 0) + self.assertEqual(load.throughput, 0) + self.assertEqual(load.iterations, 1) + + def test_get_load_str(self): + self.configure({EXEC: { + "concurrency": "2", + "hold-for": "3", + "ramp-up": "4", + "iterations": "5", + "throughput": "6", + "steps": "7", + }}) + load = self.obj.get_load() + self.assertEquals(2, load.concurrency) + self.assertEquals(3, load.hold) + self.assertEquals(4, load.ramp_up) + self.assertEquals(5, load.iterations) + self.assertEquals(6, load.throughput) + self.assertEquals(7, load.steps) + + def test_get_load_str_fail(self): + self.configure({EXEC: {"concurrency": "2VU"}}) + self.assertRaises(bzt.TaurusConfigError, self.obj.get_load) class TestK6Reader(BZTestCase): def test_read(self): From 32085e847c001bc392f1944ffa7055527910b780 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Tue, 30 Jan 2024 15:35:13 +0000 Subject: [PATCH 05/12] fix broken test --- tests/unit/modules/test_k6.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/modules/test_k6.py b/tests/unit/modules/test_k6.py index 744aee8c8..42b9f5bba 100644 --- a/tests/unit/modules/test_k6.py +++ b/tests/unit/modules/test_k6.py @@ -135,7 +135,7 @@ def test_get_load_defaults(self): self.assertEqual(load.ramp_up, None) self.assertEqual(load.concurrency, 0) self.assertEqual(load.throughput, 0) - self.assertEqual(load.iterations, 1) + self.assertEqual(load.iterations, 0) def test_get_load_str(self): self.configure({EXEC: { From 35a85364110a8269d31840d32ba6d53ad3f3fd2d Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Wed, 6 Mar 2024 13:54:19 +0000 Subject: [PATCH 06/12] fix tests to cover new get_load method --- tests/unit/modules/test_k6.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/modules/test_k6.py b/tests/unit/modules/test_k6.py index 42b9f5bba..7d06f988c 100644 --- a/tests/unit/modules/test_k6.py +++ b/tests/unit/modules/test_k6.py @@ -110,7 +110,7 @@ def test_get_load(self): self.assertEqual(self.obj.execution.get("ramp-up"), "1") self.assertEqual(self.obj.execution.get("concurrency"), "2") self.assertEqual(self.obj.execution.get("throughput"), "3") - load = self.obj.get_load() + load = self.EXECUTOR.get_load() self.assertEqual(load.ramp_up, 1) self.assertEqual(load.concurrency, 2) self.assertEqual(load.throughput, 3) @@ -121,7 +121,7 @@ def test_get_load(self): self.assertEqual(self.obj.execution.get("throughput"), {"local": "3"}) self.obj.engine.config.get("execution")[0]["concurrency"] = "22" - load = self.obj.get_load() + load = self.EXECUTOR.get_load() self.assertEqual(load.concurrency, 22) self.assertEqual(self.obj.execution.get("concurrency"), {"local": "22"}) @@ -131,7 +131,7 @@ def test_get_load_defaults(self): self.assertFalse(self.obj.execution.get("concurrency")) self.assertFalse(self.obj.execution.get("throughput")) self.assertFalse(self.obj.execution.get("iterations")) - load = self.obj.get_load() + load = self.EXECUTOR.get_load() self.assertEqual(load.ramp_up, None) self.assertEqual(load.concurrency, 0) self.assertEqual(load.throughput, 0) @@ -146,7 +146,7 @@ def test_get_load_str(self): "throughput": "6", "steps": "7", }}) - load = self.obj.get_load() + load = self.EXECUTOR.get_load() self.assertEquals(2, load.concurrency) self.assertEquals(3, load.hold) self.assertEquals(4, load.ramp_up) @@ -156,7 +156,7 @@ def test_get_load_str(self): def test_get_load_str_fail(self): self.configure({EXEC: {"concurrency": "2VU"}}) - self.assertRaises(bzt.TaurusConfigError, self.obj.get_load) + self.assertRaises(bzt.TaurusConfigError, self.EXECUTOR.get_load) class TestK6Reader(BZTestCase): def test_read(self): From 11f6c4b3a82c41e0334018ed2d3343145a3a7ac8 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Wed, 6 Mar 2024 16:25:14 +0000 Subject: [PATCH 07/12] missing self parameter --- tests/unit/modules/test_k6.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/modules/test_k6.py b/tests/unit/modules/test_k6.py index 7d06f988c..714d4cbfb 100644 --- a/tests/unit/modules/test_k6.py +++ b/tests/unit/modules/test_k6.py @@ -110,7 +110,7 @@ def test_get_load(self): self.assertEqual(self.obj.execution.get("ramp-up"), "1") self.assertEqual(self.obj.execution.get("concurrency"), "2") self.assertEqual(self.obj.execution.get("throughput"), "3") - load = self.EXECUTOR.get_load() + load = self.EXECUTOR.get_load(self) self.assertEqual(load.ramp_up, 1) self.assertEqual(load.concurrency, 2) self.assertEqual(load.throughput, 3) @@ -121,7 +121,7 @@ def test_get_load(self): self.assertEqual(self.obj.execution.get("throughput"), {"local": "3"}) self.obj.engine.config.get("execution")[0]["concurrency"] = "22" - load = self.EXECUTOR.get_load() + load = self.EXECUTOR.get_load(self) self.assertEqual(load.concurrency, 22) self.assertEqual(self.obj.execution.get("concurrency"), {"local": "22"}) @@ -131,7 +131,7 @@ def test_get_load_defaults(self): self.assertFalse(self.obj.execution.get("concurrency")) self.assertFalse(self.obj.execution.get("throughput")) self.assertFalse(self.obj.execution.get("iterations")) - load = self.EXECUTOR.get_load() + load = self.EXECUTOR.get_load(self) self.assertEqual(load.ramp_up, None) self.assertEqual(load.concurrency, 0) self.assertEqual(load.throughput, 0) @@ -146,7 +146,7 @@ def test_get_load_str(self): "throughput": "6", "steps": "7", }}) - load = self.EXECUTOR.get_load() + load = self.EXECUTOR.get_load(self) self.assertEquals(2, load.concurrency) self.assertEquals(3, load.hold) self.assertEquals(4, load.ramp_up) @@ -156,7 +156,7 @@ def test_get_load_str(self): def test_get_load_str_fail(self): self.configure({EXEC: {"concurrency": "2VU"}}) - self.assertRaises(bzt.TaurusConfigError, self.EXECUTOR.get_load) + self.assertRaises(bzt.TaurusConfigError, K6Executor.get_load) class TestK6Reader(BZTestCase): def test_read(self): From 28bcb567555640804fd6e0afef54d659db75e1b4 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Wed, 6 Mar 2024 16:38:36 +0000 Subject: [PATCH 08/12] fix broken test --- tests/unit/modules/test_k6.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/modules/test_k6.py b/tests/unit/modules/test_k6.py index 714d4cbfb..62f04c5a9 100644 --- a/tests/unit/modules/test_k6.py +++ b/tests/unit/modules/test_k6.py @@ -110,7 +110,7 @@ def test_get_load(self): self.assertEqual(self.obj.execution.get("ramp-up"), "1") self.assertEqual(self.obj.execution.get("concurrency"), "2") self.assertEqual(self.obj.execution.get("throughput"), "3") - load = self.EXECUTOR.get_load(self) + load = self.obj.get_load() self.assertEqual(load.ramp_up, 1) self.assertEqual(load.concurrency, 2) self.assertEqual(load.throughput, 3) @@ -121,7 +121,7 @@ def test_get_load(self): self.assertEqual(self.obj.execution.get("throughput"), {"local": "3"}) self.obj.engine.config.get("execution")[0]["concurrency"] = "22" - load = self.EXECUTOR.get_load(self) + load = self.obj.get_load() self.assertEqual(load.concurrency, 22) self.assertEqual(self.obj.execution.get("concurrency"), {"local": "22"}) @@ -131,7 +131,7 @@ def test_get_load_defaults(self): self.assertFalse(self.obj.execution.get("concurrency")) self.assertFalse(self.obj.execution.get("throughput")) self.assertFalse(self.obj.execution.get("iterations")) - load = self.EXECUTOR.get_load(self) + load = self.obj.get_load() self.assertEqual(load.ramp_up, None) self.assertEqual(load.concurrency, 0) self.assertEqual(load.throughput, 0) @@ -146,7 +146,7 @@ def test_get_load_str(self): "throughput": "6", "steps": "7", }}) - load = self.EXECUTOR.get_load(self) + load = self.obj.get_load() self.assertEquals(2, load.concurrency) self.assertEquals(3, load.hold) self.assertEquals(4, load.ramp_up) From dd259dd7470ddf1149e69addf54f496313155680 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Wed, 6 Mar 2024 16:39:45 +0000 Subject: [PATCH 09/12] fix test_get_load_str_fail test --- tests/unit/modules/test_k6.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/modules/test_k6.py b/tests/unit/modules/test_k6.py index 62f04c5a9..42b9f5bba 100644 --- a/tests/unit/modules/test_k6.py +++ b/tests/unit/modules/test_k6.py @@ -156,7 +156,7 @@ def test_get_load_str(self): def test_get_load_str_fail(self): self.configure({EXEC: {"concurrency": "2VU"}}) - self.assertRaises(bzt.TaurusConfigError, K6Executor.get_load) + self.assertRaises(bzt.TaurusConfigError, self.obj.get_load) class TestK6Reader(BZTestCase): def test_read(self): From 1c2d17496ad475a053794031953d2c7a06a3d441 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Wed, 6 Mar 2024 17:03:23 +0000 Subject: [PATCH 10/12] improve code coverage --- tests/unit/modules/test_k6.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/unit/modules/test_k6.py b/tests/unit/modules/test_k6.py index 42b9f5bba..5a5fda2ec 100644 --- a/tests/unit/modules/test_k6.py +++ b/tests/unit/modules/test_k6.py @@ -155,7 +155,12 @@ def test_get_load_str(self): self.assertEquals(7, load.steps) def test_get_load_str_fail(self): - self.configure({EXEC: {"concurrency": "2VU"}}) + self.configure({EXEC: { + "concurrency": "2VU", + "throughput": "1PS", + "steps": "3ST", + "iterations": "4IT" + }}) self.assertRaises(bzt.TaurusConfigError, self.obj.get_load) class TestK6Reader(BZTestCase): From 9334acdadaab27d745dc259d2ac3e8612d1416b3 Mon Sep 17 00:00:00 2001 From: "ben.pearson" Date: Thu, 7 Mar 2024 15:01:37 +0000 Subject: [PATCH 11/12] Update docymentation to include example yaml --- site/dat/docs/K6.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/site/dat/docs/K6.md b/site/dat/docs/K6.md index b4cd04fc6..38e292d06 100644 --- a/site/dat/docs/K6.md +++ b/site/dat/docs/K6.md @@ -15,6 +15,16 @@ execution: script: k6-test.js # has to be a valid K6 script ``` +For scenarios defined within the K6 script itself you can use the example below + +Example: +```yaml +execution: +- executor: k6 + scenario: + script: k6-test.js # has to be a valid K6 script +``` + Please keep in mind that it is necessary to provide a valid script to run tests. ## Script Example From 06c7c47a9732a1985223ad39ac38d2869dad4611 Mon Sep 17 00:00:00 2001 From: asos-benpearson <79104615+asos-benpearson@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:16:57 +0100 Subject: [PATCH 12/12] Update __init__.py set dev version to 0.0.1-DEV to allow local install --- bzt/resources/version/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bzt/resources/version/__init__.py b/bzt/resources/version/__init__.py index 56ea12674..a7f0fb982 100644 --- a/bzt/resources/version/__init__.py +++ b/bzt/resources/version/__init__.py @@ -1,4 +1,4 @@ -DEV_VERSION = "DEV" +DEV_VERSION = "0.0.1-DEV" try: from .version import VERSION