Skip to content

Commit 2c7f93f

Browse files
authored
Add configurable duration and VUs to load tests (#19)
1 parent 9b28474 commit 2c7f93f

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

main.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ username=$3
2222
password=$4
2323
schema_count=$5
2424
: "${schema_count:=20}"
25+
vus=$6
26+
: "${vus:=10}"
27+
duration=$7
28+
: "${duration:="5m"}"
2529

2630
stream_name=$(head /dev/urandom | tr -dc a-z | head -c10)
2731

@@ -31,7 +35,7 @@ run_smoke_test () {
3135
}
3236

3337
run_load_test () {
34-
./testcases/load_test.sh "$endpoint" "$stream_name" "$username" "$password" "$schema_count"
38+
./testcases/load_test.sh "$endpoint" "$stream_name" "$username" "$password" "$schema_count" "$vus" "$duration"
3539
return $?
3640
}
3741

testcases/load.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import http from 'k6/http';
2-
import { sleep } from 'k6';
3-
// import check from 'k6';
4-
// import exec from 'k6/execution';
2+
import { check, sleep } from 'k6';
3+
import exec from 'k6/execution';
54
import encoding from 'k6/encoding';
65
import { randomString, randomItem, randomIntBetween, uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js'
76

@@ -11,8 +10,7 @@ export const options = {
1110
contacts: {
1211
executor: 'constant-vus',
1312
vus: 10,
14-
//iterations: 200,
15-
//maxDuration: '10m',
13+
duration: "5m",
1614
},
1715
},
1816
};
@@ -174,11 +172,11 @@ export default function () {
174172

175173
let response = http.post(url, batch_requests, params);
176174

177-
//if (
178-
// !check(response[0], {
179-
// 'status code MUST be 200': (res) => res.status == 200,
180-
// })
181-
//) {
182-
// exec.test.abort("Failed to send event.. status != 200");
183-
//}
175+
if (
176+
!check(response, {
177+
'status code MUST be 200': (res) => res.status == 200,
178+
})
179+
) {
180+
exec.test.abort("Failed to send event.. status != 200");
181+
}
184182
}

testcases/load_test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ stream_name=$2
2121
username=$3
2222
password=$4
2323
count=$5
24+
vus=$6
25+
duration=$7
2426

2527
curl_std_opts=( -sS --header 'Content-Type: application/json' -w '\n\n%{http_code}' -u "$username":"$password" )
2628

@@ -81,7 +83,7 @@ delete_stream () {
8183
}
8284

8385
run_k6() {
84-
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"
86+
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"
8587
}
8688

8789
printf "======= Starting load tests with k6 =======\n"

0 commit comments

Comments
 (0)