aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/stress/test.sh
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-06-13 22:49:36 +0200
committerEgor Tensin <egor@tensin.name>2026-06-13 22:49:36 +0200
commit31ddae6f0c96d546f2fde7e3f1991210eedad6f1 (patch)
treecf6af795ef65718d896ecbd39dabd9f7bd39e75b /test/stress/test.sh
parentstress_test.py: saner output (diff)
downloadmath-server-31ddae6f0c96d546f2fde7e3f1991210eedad6f1.tar.gz
math-server-31ddae6f0c96d546f2fde7e3f1991210eedad6f1.zip
test: move stress test scripts to stress/
Diffstat (limited to 'test/stress/test.sh')
-rwxr-xr-xtest/stress/test.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/stress/test.sh b/test/stress/test.sh
new file mode 100755
index 0000000..8aa3c1d
--- /dev/null
+++ b/test/stress/test.sh
@@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+
+# Copyright (c) 2020 Egor Tensin <egor@tensin.name>
+# This file is part of the "math-server" project.
+# For details, see https://github.com/egor-tensin/math-server.
+# Distributed under the MIT License.
+
+set -o errexit -o nounset -o pipefail
+shopt -s inherit_errexit lastpipe
+
+script_name="$( basename -- "${BASH_SOURCE[0]}" )"
+readonly script_name
+script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
+script_dir="$( cd -- "$script_dir" && pwd )"
+readonly script_dir
+
+server_path=
+client_path=
+readonly stress_test_path="$script_dir/test.py"
+readonly server_port=16666
+server_pid=
+
+dump() {
+ local msg
+ for msg; do
+ echo "$script_name: $msg"
+ done
+}
+
+kill_server() {
+ dump "Killing the server with PID $server_pid..."
+ kill "$server_pid"
+ dump "Waiting for the server to terminate..."
+ wait "$server_pid"
+ dump "Done"
+}
+
+run_server() {
+ dump "Running the server..."
+ "$server_path" --port "$server_port" &
+ server_pid="$!"
+ dump "Its PID is $server_pid"
+ trap kill_server EXIT
+}
+
+run_stress_test() {
+ dump "Running stress_test.py..."
+ "$stress_test_path" \
+ --client "$client_path" \
+ --port "$server_port" \
+ --processes 4 \
+ --expressions 1000
+}
+
+script_usage() {
+ echo "usage: $script_name SERVER_PATH CLIENT_PATH"
+}
+
+parse_args() {
+ if [ "$#" -ne 2 ]; then
+ script_usage >&2
+ return 1
+ fi
+ server_path="$1"
+ client_path="$2"
+}
+
+main() {
+ parse_args "$@"
+ run_server
+ run_stress_test
+}
+
+main "$@"