Skip to content

Commit e483a1d

Browse files
committed
add script for testing task runtime
1 parent f889672 commit e483a1d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/test-runtime.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# set the Slack token here!
4+
export SLACK_CLI_TOKEN=
5+
export PATH=$PATH:/usr/local/bin:$HOME/loda/bin
6+
7+
if [ -z "$SLACK_CLI_TOKEN" ]; then
8+
echo "Error: SLACK_CLI_TOKEN is not set"
9+
exit 1
10+
fi
11+
12+
for cmd in slack git; do
13+
if ! [ -x "$(command -v $cmd)" ]; then
14+
echo "Error: $cmd is not installed" >&2
15+
exit 1
16+
fi
17+
done
18+
19+
pushd .. > /dev/null
20+
21+
# rebuild
22+
git pull
23+
COMMIT=$(git rev-parse HEAD)
24+
pushd src > /dev/null
25+
make clean ; make
26+
popd > /dev/null
27+
28+
# start miner (2 hours)
29+
PROFILE=update
30+
./loda mine -i $PROFILE -H 2 &
31+
PID=$!
32+
33+
START_TIME=$SECONDS
34+
WARN_TIME=7200
35+
ERR_TIME=14400
36+
37+
while true; do
38+
# check if the process is still running
39+
if ! ps -p $PID > /dev/null; then
40+
break
41+
fi
42+
# check runtime
43+
DURATION=$((SECONDS - START_TIME))
44+
if (( DURATION > ERR_TIME )); then
45+
kill $PID
46+
break
47+
fi
48+
sleep 10
49+
done
50+
51+
DURATION=$((SECONDS - START_TIME))
52+
if (( DURATION > ERR_TIME )); then
53+
TEXT="Task exceeded time limit"
54+
COLOR="danger"
55+
elif (( DURATION > WARN_TIME )); then
56+
TEXT="Task ran unusually long"
57+
COLOR="warning"
58+
else
59+
TEXT="Task finished on time"
60+
COLOR="good"
61+
fi
62+
slack chat send --text "${TEXT}: ${DURATION}s; profile: $PROFILE; commit: $COMMIT" --color "$COLOR" --channel "#test-runtime"
63+
64+
popd > /dev/null

0 commit comments

Comments
 (0)