Skip to content

Commit 08b1cb3

Browse files
authored
Add a validation mode (#27)
Fixes #26
1 parent 3fc7639 commit 08b1cb3

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ Positional arguments for the 'smoke' or 'load' mode:
2828
4. Password
2929
```
3030

31-
3231
Additional positional arguments for the 'load' mode
3332
```
34-
5. (Optional) Number of different json formats to send to a stream
35-
6. (Optional) Schema count
36-
7. (Optional) Duration
33+
5. (Optional) Number of different json schemas to send to a stream
34+
6. (Optional) Number of virtual users (Refer K6 [documentation on VUs](https://k6.io/docs/get-started/running-k6/#adding-more-vus))
35+
7. (Optional) Duration of the test
3736
```
3837

3938
Example usage:

main.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ run_load_test () {
3939
return $?
4040
}
4141

42+
run_validation_test () {
43+
./testcases/validate_test.sh "$endpoint" "$stream_name" "$username" "$password" "$schema_count" "$vus" "$duration"
44+
return $?
45+
}
46+
4247
case "$mode" in
4348
"smoke") run_smoke_test
4449
;;
4550
"load") run_load_test
4651
;;
52+
"validate") run_validation_test
53+
;;
4754
esac

testcases/validate_test.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
#
3+
# Parseable Server (C) 2023 Cloudnatively Pvt. Ltd.
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as
7+
# published by the Free Software Foundation, either version 3 of the
8+
# License, or (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
19+
parseable_url=$1
20+
stream_name="backend"
21+
username=$3
22+
password=$4
23+
count=$5
24+
vus=$6
25+
duration=$7
26+
27+
curl_std_opts=( -sS --header 'Content-Type: application/json' -w '\n\n%{http_code}' -u "$username":"$password" )
28+
29+
# Create stream
30+
create_stream () {
31+
response=$(curl "${curl_std_opts[@]}" --request PUT "$parseable_url"/api/v1/logstream/"$stream_name")
32+
33+
if [ $? -ne 0 ]; then
34+
printf "Failed to create log stream %s with exit code: %s\n" "$stream_name" "$?"
35+
printf "Test create_stream: failed\n"
36+
exit 1
37+
fi
38+
39+
http_code=$(tail -n1 <<< "$response")
40+
if [ "$http_code" -ne 200 ]; then
41+
printf "Failed to create log stream %s with http code: %s and response: %s\n" "$stream_name" "$http_code" "$content"
42+
printf "Test create_stream: failed\n"
43+
exit 1
44+
fi
45+
46+
content=$(sed '$ d' <<< "$response")
47+
if [ "$content" != "log stream created" ]; then
48+
printf "Failed to create log stream $stream_name with response: %s\n" "$content"
49+
printf "Test create_stream: failed\n"
50+
exit 1
51+
fi
52+
53+
printf "Test create_stream: successful\n"
54+
return 0
55+
}
56+
57+
run_k6() {
58+
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/smoke.js" --vus="$vus" --duration="$duration"
59+
}
60+
61+
printf "======= Starting validation tests with k6 =======\n"
62+
printf "** Log stream name: %s **\n" "$stream_name"
63+
printf "====================================\n"
64+
create_stream
65+
run_k6
66+
printf "======= Load tests completed ======\n"

0 commit comments

Comments
 (0)