-
Notifications
You must be signed in to change notification settings - Fork 5
/
runtests_server.sh
executable file
·185 lines (138 loc) · 4.08 KB
/
runtests_server.sh
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
set -x
set -o errexit
#set -o nounset
set -o pipefail
if [[ $# -lt 2 || ( "$1" != benchmark && "$1" != "test" && "$1" != "setup" ) ]];
then
echo "Usage: "
echo " $0 benchmark output-name [server_branch[|rev_number]] [web_branch[|rev_number]] [-t tag]"
echo " $0 test output-name [server_branch[|rev_number]] [web_branch[|rev_number]] [-t tag]"
exit 1
fi
source config.sh
################################################################
# Fetch the time difference between the date we want to use to run the tests
DATEUTILS=date
if [[ $(uname) == Darwin ]]
then
DATEUTILS=gdate
fi
BEFORE=$($DATEUTILS -d "2016-05-25" '+%s')
NOW=$($DATEUTILS '+%s')
if [[ ${FORCED_DATE} == yes ]];
then
MINUS_IN_SECOND=$[ $NOW - $BEFORE ]
else
MINUS_IN_SECOND=0
fi
#################################################################
VERB=${1:-test}
ENVNAME=$SERVER_ENVNAME
NAME=${2:-unkown}
SERVERBRANCH=${3:-lp:unifield-server}
WEBBRANCH=${4:-lp:unifield-web}
if [[ -z ${LETTUCE_PARAMS} ]]; then
LETTUCE_PARAMS="${*:5}"
fi
function cleanup()
{
if [[ $VERB != setup ]];
then
./scripts/kill_db.sh -D $SERVER_TMPDIR $NAME || true
./scripts/stop_unifield.sh -d $SERVER_TMPDIR $NAME || true
fi
}
trap "cleanup;" EXIT
export PGPASSWORD=$DBPASSWORD
run_tests()
{
RET=0
case $VERB in
test|setup)
export TIME_BEFORE_FAILURE=${TIME_BEFORE_FAILURE:-40}
export COUNT=5
export TEST_DESCRIPTION=${TEST_DESCRIPTION:-$NAME}
export TEST_NAME=${TEST_NAME:-$NAME}
export TEST_DATE=$($DATEUTILS '+%Y/%m/%d')
rm output/* || true
./runtests_local.sh -s $MINUS_IN_SECOND $LETTUCE_PARAMS || RET=1
DIREXPORT=website/tests/$($DATEUTILS '+%Y%m%d%H%M')_$NAME
if [[ -e "$DIREXPORT" ]]
then
rm -rf "$DIREXPORT" || true
fi
mkdir -p "$DIREXPORT"
./scripts/start_unifield.sh -d $SERVER_TMPDIR version $NAME > output/version
./scripts/start_unifield.sh -d $SERVER_TMPDIR logs $NAME > output/server.log
cp -R output/* $DIREXPORT/ || true
;;
benchmark)
rm -rf results/* 2> /dev/null || true
export TIME_BEFORE_FAILURE=
# If they did not tell us what tags to use, then
# default to testing @testperf features.
if [ -z "$LETTUCE_PARAMS" ]; then
LETTUCE_PARAMS="-t testperf"
fi
for count in 5 15 25 35 45
do
export COUNT=$count
# run the benchmark
for nb in `seq 1 4`;
do
./runtests_local.sh -s $MINUS_IN_SECOND $LETTUCE_PARAMS || true
done
done
DIREXPORT="website/performances/$NAME"
if [[ -e "$DIREXPORT" ]]
then
rm -rf "$DIREXPORT" || true
fi
mkdir -p "$DIREXPORT"
cp -R results/* "$DIREXPORT/"
;;
esac
return $RET
}
launch_database()
{
if [[ $DBUSERNAME != $DBPASSWORD ]]
then
echo Username and password must be the same if you want to set a fixed date
exit 1
fi
./scripts/create_db.sh -P ${DBPATH} -D $SERVER_TMPDIR -s $MINUS_IN_SECOND -p $DBPORT -c $DBUSERNAME $NAME
}
DATABASES=
for FILENAME in `find instances/$ENVNAME -name *.dump | sort`;
do
F_WITHOUT_EXTENSION=${FILENAME%.dump}
DBNAME=${F_WITHOUT_EXTENSION##*/}
DATABASES="$DATABASES $DBNAME"
done
export DATABASES=$DATABASES
./generate_credentials.sh
mkdir -p $SERVER_TMPDIR
./scripts/fetch_unifield.sh -W "$WEBBRANCH" -S "$SERVERBRANCH" \
-d $SERVER_TMPDIR -r $NAME
# we have to setup a database if required
if [[ ${DBPATH} && ${FORCED_DATE} == yes ]];
then
launch_database
else
FORCED_DATE=no
fi
if [ -z "$NORESTORE" ]; then
if [[ ${FORCED_DATE} == yes ]]
then
python restore.py --reset-sync --reset-versions $ENVNAME
else
python restore.py --reset-versions $ENVNAME
fi
fi
./scripts/upgrade_unifield.sh -s $MINUS_IN_SECOND -d $SERVER_TMPDIR $NAME $ENVNAME
./scripts/start_unifield.sh -s $MINUS_IN_SECOND -d $SERVER_TMPDIR run $NAME
RET=0
run_tests || RET=$?
#exit $RET