-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestrunner.sh
More file actions
executable file
·117 lines (101 loc) · 2.97 KB
/
testrunner.sh
File metadata and controls
executable file
·117 lines (101 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# This script is run via a systemd timer. The service and timer files lie in /lib/systemd/system
# (and are called testrunner.service and testrunner.timer, respectively).
# This script is not intended to be run manually.
# Don't run twice
if [ -f ~/test/mutex ]; then
echo "Mutex exists already!"
# This is disabled for now, since systemd *should* already ensure this doesn't run twice.
# If this case occurs then, probably something went wrong with the mutex. If the test is
# ever run outside of systemd timers, this becomes relevant again.
#exit 0
fi
touch ~/test/mutex
# Check status of badgr-ui
cd ~/docker/badgr-ui
uiNew=`docker compose exec ui ls newVersion 2> /dev/null`
if [ -n "$uiNew" ]; then
uiTime=`docker compose exec -T ui stat -c"%Z" newVersion`
else
uiTime=0
fi
# Check status of badgr-server
cd ~/docker/badgr-server
serverNew=`docker compose exec -T api ls newVersion 2> /dev/null`
if [ -n "$serverNew" ]; then
serverTime=`docker compose exec -T api stat -c "%Z" newVersion`
else
serverTime=0
fi
# Check status of oeb-test
cd ~/test/oeb-test
testNew=`git pull | grep --quiet -v "Already up to date." && echo "new"`
if [ -z "$uiNew" ]; then
if [ -z "$serverNew" ]; then
if [ -z "$testNew" ]; then
echo "Nothing new!"
rm ~/test/mutex
exit 0
fi
fi
fi
echo "Something is new!"
if [ -z "$testNew" ]; then
newestTime=`echo -e "$serverTime\n$uiTime" | sort -n | tail -1`
currentTime=`date +%s`
elapsed=$((currentTime - newestTime))
echo "Elapsed time: $elapsed"
# Wait 60s after update to give the application time to settle
if [ $elapsed -lt 60 ]; then
rm ~/test/mutex
exit 0
fi
else
echo "New tests found"
fi
# Delete newVersion indicator in containers
if [ -n "$uiNew" ]; then
cd ~/docker/badgr-ui
docker compose exec ui rm newVersion
fi
if [ -n "$serverNew" ]; then
cd ~/docker/badgr-server
docker compose exec api rm newVersion
fi
echo "Initiating tests!"
cd ~/test/oeb-test
# Updating test repository
git pull
# Preserve exit code
set -o pipefail
timeout 30m docker compose run node 2>&1 | tee ~/test/test_output.log
exitCode=$?
echo "Exit code is $exitCode"
# Shutdown the containers, to kill off residues of the test run that might interfere with future ones
docker compose down
cd ~/test
attachmentString=`./failingScreenshots.sh | ./attachImages.sh`
if [ "$exitCode" -eq "0" ]; then
echo "Successful!"
# Only notify if the last test failed
if [ -f lastFailed ]; then
echo "Fixed! All tests successful again." | ./notify.sh
rm lastFailed
fi
elif [ "$exitCode" -eq "124" ]; then
echo "Timeout!"
if [ "$attachmentString" == "" ]; then
echo "Tests timed out! No errors were detected though. Log:" | ./notify.sh
./notify.sh < test_output.log
else
echo "Tests timed out! They seem to have failed. Log:" | ./notify.sh
./notify.sh "$attachmentString" < test_output.log
touch lastFailed
fi
else
echo "Failed!"
echo "Tests failed! Log:" | ./notify.sh
./notify.sh "$attachmentString" < test_output.log
touch lastFailed
fi
rm ~/test/mutex