From fae3f5e734ab921b76ecc1b8432f0ce29375e37c Mon Sep 17 00:00:00 2001 From: Olha Yevtushenko Date: Thu, 9 Mar 2023 10:47:14 +0200 Subject: [PATCH] e2e: add some key test cases --- e2e/tests/abort-all.js | 25 ++++++++++++++++++++ e2e/tests/abort-one-runner.js | 26 +++++++++++++++++++++ e2e/tests/cloudoutput_fail-and-abort.js | 31 +++++++++++++++++++++++++ e2e/tests/cloudoutput_fail.js | 29 +++++++++++++++++++++++ e2e/tests/cloudoutput_pass-long-fmt.js | 31 +++++++++++++++++++++++++ e2e/tests/cloudoutput_pass.js | 25 ++++++++++++++++++++ e2e/tests/one-runner-delayed.js | 28 ++++++++++++++++++++++ 7 files changed, 195 insertions(+) create mode 100644 e2e/tests/abort-all.js create mode 100644 e2e/tests/abort-one-runner.js create mode 100644 e2e/tests/cloudoutput_fail-and-abort.js create mode 100644 e2e/tests/cloudoutput_fail.js create mode 100644 e2e/tests/cloudoutput_pass-long-fmt.js create mode 100644 e2e/tests/cloudoutput_pass.js create mode 100644 e2e/tests/one-runner-delayed.js diff --git a/e2e/tests/abort-all.js b/e2e/tests/abort-all.js new file mode 100644 index 00000000..62578fab --- /dev/null +++ b/e2e/tests/abort-all.js @@ -0,0 +1,25 @@ +import http from 'k6/http'; +import { check } from 'k6'; +import exec from 'k6/execution'; + +export let options = { + stages: [ + { target: 200, duration: '30s' }, + { target: 0, duration: '30s' }, + ], +}; + +export default function () { + const result = http.get('https://test-api.k6.io/public/crocodiles/'); + check(result, { + 'http response status code is 200': result.status === 200, + }); + + // abort at some random point in the 2nd half of the test + if (exec.scenario.progress > 0.5) { + const rnd = Math.floor(Math.random() * 100); + if (rnd > 50) { + exec.test.abort(); + } + } +} diff --git a/e2e/tests/abort-one-runner.js b/e2e/tests/abort-one-runner.js new file mode 100644 index 00000000..742323bd --- /dev/null +++ b/e2e/tests/abort-one-runner.js @@ -0,0 +1,26 @@ +import http from 'k6/http'; +import { check } from 'k6'; +import exec from 'k6/execution'; + +export let options = { + stages: [ + { target: 200, duration: '30s' }, + { target: 0, duration: '30s' }, + ], +}; + +export default function () { + const result = http.get('https://test-api.k6.io/public/crocodiles/'); + check(result, { + 'http response status code is 200': result.status === 200, + }); + + // abort the 1st instance at some random point in the 2nd half of the test + const instanceId = exec.test.options.tags["instance_id"]; + if (instanceId == 1 && exec.scenario.progress > 0.5) { + const rnd = Math.floor(Math.random() * 100); + if (rnd > 50) { + exec.test.abort(); + } + } +} diff --git a/e2e/tests/cloudoutput_fail-and-abort.js b/e2e/tests/cloudoutput_fail-and-abort.js new file mode 100644 index 00000000..30855892 --- /dev/null +++ b/e2e/tests/cloudoutput_fail-and-abort.js @@ -0,0 +1,31 @@ +import http from 'k6/http'; +import { check } from 'k6'; + +export let options = { + stages: [ + { target: 100, duration: '1m30s' }, + { target: 200, duration: '30s' }, + { target: 0, duration: '30s' }, + ], + thresholds: { + http_req_duration: [ + { + threshold: 'p(99) < 200', + abortOnFail: true, + delayAbortEval: '10s', + }, + ], + }, + ext: { + loadimpact: { + name: 'Configured k6-operator test', + } + } +}; + +export default function () { + const result = http.get('https://test-api.k6.io/public/crocodiles/'); + check(result, { + 'http response status code is 200': result.status === 200, + }); +} diff --git a/e2e/tests/cloudoutput_fail.js b/e2e/tests/cloudoutput_fail.js new file mode 100644 index 00000000..0d0b1500 --- /dev/null +++ b/e2e/tests/cloudoutput_fail.js @@ -0,0 +1,29 @@ +import http from 'k6/http'; +import { check } from 'k6'; + +export let options = { + stages: [ + { target: 100, duration: '1m30s' }, + { target: 200, duration: '30s' }, + { target: 0, duration: '30s' }, + ], + thresholds: { + http_req_duration: [ + { + threshold: 'p(99) < 200', + }, + ], + }, + ext: { + loadimpact: { + name: 'Configured k6-operator test', + } + } +}; + +export default function () { + const result = http.get('https://test-api.k6.io/public/crocodiles/'); + check(result, { + 'http response status code is 200': result.status === 200, + }); +} diff --git a/e2e/tests/cloudoutput_pass-long-fmt.js b/e2e/tests/cloudoutput_pass-long-fmt.js new file mode 100644 index 00000000..4d6a8f67 --- /dev/null +++ b/e2e/tests/cloudoutput_pass-long-fmt.js @@ -0,0 +1,31 @@ +import http from 'k6/http'; +import { check } from 'k6'; + +export let options = { + stages: [ + { target: 100, duration: '1m30s' }, + { target: 200, duration: '5m30s' }, + { target: 0, duration: '30s' }, + ], + thresholds: { + http_req_duration: [ + { + threshold: 'p(95)<20000', + abortOnFail: true, + delayAbortEval: '10s', + }, + ], + }, + ext: { + loadimpact: { + name: 'Configured k6-operator test', + } + } +}; + +export default function () { + const result = http.get('https://test-api.k6.io/public/crocodiles/'); + check(result, { + 'http response status code is 200': result.status === 200, + }); +} diff --git a/e2e/tests/cloudoutput_pass.js b/e2e/tests/cloudoutput_pass.js new file mode 100644 index 00000000..bd955f6f --- /dev/null +++ b/e2e/tests/cloudoutput_pass.js @@ -0,0 +1,25 @@ +import http from 'k6/http'; +import { check } from 'k6'; + +export let options = { + stages: [ + { target: 100, duration: '1m30s' }, + { target: 200, duration: '5m30s' }, + { target: 0, duration: '30s' }, + ], + thresholds: { + http_req_duration: ['p(95)<20000'], + }, + ext: { + loadimpact: { + name: 'Configured k6-operator test', + } + } +}; + +export default function () { + const result = http.get('https://test-api.k6.io/public/crocodiles/'); + check(result, { + 'http response status code is 200': result.status === 200, + }); +} diff --git a/e2e/tests/one-runner-delayed.js b/e2e/tests/one-runner-delayed.js new file mode 100644 index 00000000..3d7f0d82 --- /dev/null +++ b/e2e/tests/one-runner-delayed.js @@ -0,0 +1,28 @@ +import http from 'k6/http'; +import { check, sleep } from 'k6'; +import exec from 'k6/execution'; + +export let options = { + scenarios: { + default: { + executor: 'per-vu-iterations', + vus: 10, + iterations: 10, + maxDuration: '1m30s' + } + } +}; + +export default function () { + // delay the 1st instance from executing to simulate a delay + const instanceId = exec.test.options.tags["instance_id"]; + if (instanceId == 1 && exec.scenario.iterationInInstance == 0) { + sleep(60); + } + + + const result = http.get('https://test-api.k6.io/public/crocodiles/'); + check(result, { + 'http response status code is 200': result.status === 200, + }); +}