|
| 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