1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/tests/integration/api-stress.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
1.7 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
2017-09-04 10:39:40 +02:00
#
# Stress test for remote API
#
2022-03-15 09:18:01 -04:00
# Author: Steffen Vogel <post@steffenvogel.de>
2022-03-15 09:28:57 -04:00
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
2022-07-04 18:20:03 +02:00
# SPDX-License-Identifier: Apache-2.0
2017-09-04 10:39:40 +02:00
set -e
set -x
DIR=$(mktemp -d)
pushd ${DIR}
function finish {
popd
rm -rf ${DIR}
}
trap finish EXIT
2021-09-22 13:30:26 +02:00
LOCAL_CONF=${SRCDIR}/etc/loopback.json
2017-09-04 10:39:40 +02:00
2021-02-16 14:15:14 +01:00
# Start VILLASnode instance with local config
2021-09-22 10:42:03 +02:00
villas node ${LOCAL_CONF} &
2017-09-04 10:39:40 +02:00
# Wait for node to complete init
sleep 1
2018-08-20 18:32:01 +02:00
RUNS=100
2017-09-04 10:39:40 +02:00
FAILED=0
SUCCESS=0
FIFO=$(mktemp -p ${DIR} -t fifo.XXXXXX -u)
2017-09-04 10:39:40 +02:00
mkfifo ${FIFO}
# Fifo must be opened in both directions!
# https://www.gnu.org/software/libc/manual/html_node/FIFO-Special-Files.html#FIFO-Special-Files
2018-08-20 18:32:01 +02:00
# Quote: "However, it has to be open at both ends simultaneously before you can proceed to
# do any input or output operations on it"
2017-09-04 10:39:40 +02:00
exec 5<>${FIFO}
JOBS=""
2018-12-04 00:30:44 +01:00
for J in $(seq 1 ${RUNS}); do
(
set -e
trap "echo error-trap >> ${FIFO}" ERR
FETCHED_CONF=$(mktemp -p ${DIR})
curl -s http://localhost:8080/api/v2/config > ${FETCHED_CONF}
diff -u <(jq -S . < ${FETCHED_CONF}) <(jq -S . < ${LOCAL_CONF})
RC=$?
if [ "$RC" -eq "0" ]; then
echo success >&5
else
echo error >&5
fi
) &
JOBS+=" $!"
2017-09-04 10:39:40 +02:00
done
echo "Waiting for jobs to complete: ${JOBS}"
wait ${JOBS}
kill %1
wait %1
2017-09-04 10:39:40 +02:00
echo "Check return codes"
2018-12-04 00:30:44 +01:00
for J in $(seq 1 ${RUNS}); do
read -t 10 -u 5 STATUS
if [ "${STATUS}" == "success" ]; then
let ++SUCCESS
else
let ++FAILED
fi
2017-09-04 10:39:40 +02:00
done
2018-08-20 18:32:01 +02:00
echo "Success: ${SUCCESS} / ${RUNS}"
echo "Failed: ${FAILED} / ${RUNS}"
(( ${FAILED} == 0 ))