From 92c1d0c4c62b5960e0556d8a41b9ae4aaf0abbd1 Mon Sep 17 00:00:00 2001 From: Satyam Singh Date: Tue, 16 May 2023 20:26:21 +0530 Subject: [PATCH 1/2] Fix load test --- testcases/load.js | 22 ++++++++++------------ testcases/load_test.sh | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/testcases/load.js b/testcases/load.js index 2f16b67..34b1ecb 100644 --- a/testcases/load.js +++ b/testcases/load.js @@ -1,7 +1,6 @@ import http from 'k6/http'; -import { sleep } from 'k6'; -// import check from 'k6'; -// import exec from 'k6/execution'; +import { check, sleep } from 'k6'; +import exec from 'k6/execution'; import encoding from 'k6/encoding'; import { randomString, randomItem, randomIntBetween, uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js' @@ -11,8 +10,7 @@ export const options = { contacts: { executor: 'constant-vus', vus: 10, - //iterations: 200, - //maxDuration: '10m', + duration: "5m", }, }, }; @@ -174,11 +172,11 @@ export default function () { let response = http.post(url, batch_requests, params); - //if ( - // !check(response[0], { - // 'status code MUST be 200': (res) => res.status == 200, - // }) - //) { - // exec.test.abort("Failed to send event.. status != 200"); - //} + if ( + !check(response, { + 'status code MUST be 200': (res) => res.status == 200, + }) + ) { + exec.test.abort("Failed to send event.. status != 200"); + } } diff --git a/testcases/load_test.sh b/testcases/load_test.sh index 70432ac..39be2a5 100755 --- a/testcases/load_test.sh +++ b/testcases/load_test.sh @@ -81,7 +81,7 @@ delete_stream () { } run_k6() { - k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load.js" + k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load.js" --vus=10 --duration="5m" } printf "======= Starting load tests with k6 =======\n" From 95e71a2ef0ca43ff0428a5b06e69c330c8f33b88 Mon Sep 17 00:00:00 2001 From: Satyam Singh Date: Tue, 16 May 2023 21:55:33 +0530 Subject: [PATCH 2/2] Make args --- main.sh | 6 +++++- testcases/load_test.sh | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/main.sh b/main.sh index c7ac247..52c8cb7 100755 --- a/main.sh +++ b/main.sh @@ -22,6 +22,10 @@ username=$3 password=$4 schema_count=$5 : "${schema_count:=20}" +vus=$6 +: "${vus:=10}" +duration=$7 +: "${duration:="5m"}" stream_name=$(head /dev/urandom | tr -dc a-z | head -c10) @@ -31,7 +35,7 @@ run_smoke_test () { } run_load_test () { - ./testcases/load_test.sh "$endpoint" "$stream_name" "$username" "$password" "$schema_count" + ./testcases/load_test.sh "$endpoint" "$stream_name" "$username" "$password" "$schema_count" "$vus" "$duration" return $? } diff --git a/testcases/load_test.sh b/testcases/load_test.sh index 39be2a5..4e8e20f 100755 --- a/testcases/load_test.sh +++ b/testcases/load_test.sh @@ -21,6 +21,8 @@ stream_name=$2 username=$3 password=$4 count=$5 +vus=$6 +duration=$7 curl_std_opts=( -sS --header 'Content-Type: application/json' -w '\n\n%{http_code}' -u "$username":"$password" ) @@ -81,7 +83,7 @@ delete_stream () { } run_k6() { - k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load.js" --vus=10 --duration="5m" + k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load.js" --vus="$vus" --duration="$duration" } printf "======= Starting load tests with k6 =======\n"