-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·366 lines (308 loc) · 8.91 KB
/
test.sh
File metadata and controls
executable file
·366 lines (308 loc) · 8.91 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#!/usr/bin/env bash
echo "First arg:"
echo $1
os='linux'
if [ "X$1" = "X-w" ]; then
os='windows'
fi
echo "OS:" $os
src_dir=$(pwd)
test_root=build/lib/tests
if [ "X$os" = "Xwindows" ]; then
test_root=$test_root/Debug
fi
if [ "X$os" = "Xlinux" ]; then
drogon_ctl_exec=$(pwd)/build/drogon_ctl/drogon_ctl
else
drogon_ctl_exec=$(pwd)/build/drogon_ctl/Debug/drogon_ctl.exe
export PATH=$PATH:$src_dir/install/bin
fi
echo "drogon_ctl_exec: " ${drogon_ctl_exec}
if [ "X$os" = "Xwindows" ]; then
integration_test_client_exec=./integration_test_client.exe
integration_test_server_exec=./integration_test_server.exe
else
integration_test_client_exec=./integration_test_client
integration_test_server_exec=./integration_test_server
fi
function update_config_line()
{
local key="$1"
local value="$2"
local file="$3"
sed -i.bak -e "s/\"${key}\".*$/\"${key}\": ${value},/" "$file"
rm -f "$file.bak"
}
function cleanup_integration_test_server()
{
if [ "X$os" = "Xwindows" ]; then
taskkill //F //IM integration_test_server.exe > /dev/null 2>&1 || true
else
killall integration_test_server > /dev/null 2>&1 || true
pkill -f '/integration_test_server$' > /dev/null 2>&1 || true
fi
}
function wait_for_url()
{
local url="$1"
local timeout_seconds="$2"
local curl_args=(--silent --show-error --output /dev/null --max-time 2)
if [ "$url" != "${url#https://}" ]; then
curl_args+=(--insecure)
fi
local attempt=0
while [ $attempt -lt $timeout_seconds ]; do
if curl "${curl_args[@]}" "$url"; then
return 0
fi
attempt=$((attempt + 1))
sleep 1
done
return 1
}
function wait_for_integration_test_server()
{
local server_pid="$1"
local server_log="$2"
if ! wait_for_url "http://127.0.0.1:8848/" 30; then
echo "Timed out waiting for integration_test_server to accept HTTP requests"
if kill -0 "$server_pid" > /dev/null 2>&1; then
echo "integration_test_server is still running, recent log output:"
else
echo "integration_test_server exited before becoming ready, recent log output:"
fi
if [ -f "$server_log" ]; then
tail -n 50 "$server_log"
fi
return 1
fi
wait_for_url "https://127.0.0.1:8849/" 5 > /dev/null 2>&1 || true
return 0
}
function get_cpu_count()
{
if command -v nproc > /dev/null 2>&1; then
nproc
return
fi
if command -v getconf > /dev/null 2>&1; then
getconf _NPROCESSORS_ONLN
return
fi
if command -v sysctl > /dev/null 2>&1; then
sysctl -n hw.logicalcpu
return
fi
echo 1
}
trap cleanup_integration_test_server EXIT
# Run the integration test server in the background and wait until it is ready.
function do_integration_test()
{
pushd "$test_root"
update_config_line "run_as_daemon" "false" config.example.json
update_config_line "relaunch_on_error" "false" config.example.json
update_config_line "number_of_threads" "1" config.example.json
update_config_line "use_brotli" "true" config.example.json
if [ "$1" = "stream_mode" ]; then
update_config_line "enable_request_stream" "true" config.example.json
else
update_config_line "enable_request_stream" "false" config.example.json
fi
if [ ! -f "$integration_test_client_exec" ]; then
echo "Build failed"
exit -1
fi
if [ ! -f "$integration_test_server_exec" ]; then
echo "Build failed"
exit -1
fi
cleanup_integration_test_server
local server_log=integration_test_server.log
rm -f "$server_log"
"$integration_test_server_exec" > "$server_log" 2>&1 &
local server_pid=$!
if ! wait_for_integration_test_server "$server_pid" "$server_log"; then
exit -1
fi
echo "Running the integration test $1"
"$integration_test_client_exec" -s
if [ $? -ne 0 ]; then
echo "Integration test failed $1"
if [ -f "$server_log" ]; then
tail -n 50 "$server_log"
fi
exit -1
fi
cleanup_integration_test_server
popd
}
#Test drogon_ctl
function do_drogon_ctl_test()
{
echo "Testing drogon_ctl"
pushd "$test_root"
rm -rf drogon_test
${drogon_ctl_exec} create project drogon_test
ls -la
cd drogon_test/controllers
${drogon_ctl_exec} create controller Test::SimpleCtrl
${drogon_ctl_exec} create controller -h Test::HttpCtrl
${drogon_ctl_exec} create controller -w Test::WebsockCtrl
${drogon_ctl_exec} create controller SimpleCtrl
${drogon_ctl_exec} create controller -h HttpCtrl
${drogon_ctl_exec} create controller -w WebsockCtrl
if [ ! -f "Test_SimpleCtrl.h" -o ! -f "Test_SimpleCtrl.cc" -o ! -f "Test_HttpCtrl.h" -o ! -f "Test_HttpCtrl.cc" -o ! -f "Test_WebsockCtrl.h" -o ! -f "Test_WebsockCtrl.cc" ]; then
echo "Failed to create controllers"
exit -1
fi
if [ ! -f "SimpleCtrl.h" -o ! -f "SimpleCtrl.cc" -o ! -f "HttpCtrl.h" -o ! -f "HttpCtrl.cc" -o ! -f "WebsockCtrl.h" -o ! -f "WebsockCtrl.cc" ]; then
echo "Failed to create controllers"
exit -1
fi
cd ../filters
${drogon_ctl_exec} create filter Test::TestFilter
if [ ! -f "Test_TestFilter.h" -o ! -f "Test_TestFilter.cc" ]; then
echo "Failed to create filters"
exit -1
fi
cd ../plugins
${drogon_ctl_exec} create plugin Test::TestPlugin
if [ ! -f "Test_TestPlugin.h" -o ! -f "Test_TestPlugin.cc" ]; then
echo "Failed to create plugins"
exit -1
fi
cd ../views
echo "Hello, world!" >>hello.csp
cd ../build
make_flags=''
cmake_gen=''
parallel=1
cpu_count=$(get_cpu_count)
# simulate ninja's parallelism
case $cpu_count in
1)
parallel=$((cpu_count + 1))
;;
2)
parallel=$((cpu_count + 1))
;;
*)
parallel=$((cpu_count + 2))
;;
esac
if [ "X$os" = "Xlinux" ]; then
if command -v ninja > /dev/null 2>&1; then
cmake_gen='-G Ninja'
else
make_flags="$make_flags -j$parallel"
fi
else
cmake_gen="$cmake_gen -DCMAKE_TOOLCHAIN_FILE=$src_dir/conan_toolchain.cmake \
-DCMAKE_PREFIX_PATH=$src_dir/install \
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW \
-DCMAKE_CXX_STANDARD=17"
fi
cmake .. $cmake_gen
if [ $? -ne 0 ]; then
echo "Failed to run CMake for example project"
exit -1
fi
cmake --build . -- $make_flags
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
if [ "X$os" = "Xlinux" ]; then
if [ ! -f "drogon_test" ]; then
echo "Failed to build drogon_test"
exit -1
fi
else
if [ ! -f "Debug\drogon_test.exe" ]; then
echo "Failed to build drogon_test"
exit -1
fi
fi
cd ../../
rm -rf drogon_test
popd
}
#unit testing
function do_unittest()
{
echo "Unit testing"
pushd "$src_dir/build"
ctest . --output-on-failure
if [ $? -ne 0 ]; then
echo "Error in unit testing"
exit -1
fi
popd
}
function do_db_test()
{
pushd "$src_dir/build"
if [ -f "./orm_lib/tests/db_test" ]; then
echo "Test database"
./orm_lib/tests/db_test -s
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
fi
if [ -f "./orm_lib/tests/pipeline_test" ]; then
echo "Test pipeline mode"
./orm_lib/tests/pipeline_test -s
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
fi
if [ -f "./orm_lib/tests/db_listener_test" ]; then
echo "Test DbListener"
./orm_lib/tests/db_listener_test -s
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
fi
if [ -f "./orm_lib/tests/conn_options_test" ]; then
echo "Test connection options"
./orm_lib/tests/conn_options_test -s
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
fi
if [ -f "./orm_lib/tests/db_api_test" ]; then
echo "Test getDbClient() api"
./orm_lib/tests/db_api_test -s
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
fi
if [ -f "./nosql_lib/redis/tests/redis_test" ]; then
echo "Test redis"
./nosql_lib/redis/tests/redis_test -s
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
fi
}
if [ ! -f "$drogon_ctl_exec" ]
then
echo "Warning: No built drogon_ctl, skip integration test and drogon_ctl test"
else
do_integration_test
do_integration_test stream_mode
do_drogon_ctl_test
fi
if [ "X$1" = "X-t" ]; then
do_unittest
do_db_test
fi
echo "Everything is ok!"
exit 0