修复: 升级框架并完善报告导出
- 升级 Drogon 和 Trantor,修复畸形请求导致的连接计数泄漏\n- 增加第三方框架版本校验与自动重建\n- 完善完整报告导出和接口文档
This commit is contained in:
Vendored
+134
-32
@@ -23,46 +23,147 @@ else
|
||||
fi
|
||||
echo "drogon_ctl_exec: " ${drogon_ctl_exec}
|
||||
|
||||
#Make integration_test_server run as a daemon
|
||||
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
|
||||
if [ "X$os" = "Xlinux" ]; then
|
||||
sed -i -e "s/\"run_as_daemon.*$/\"run_as_daemon\": true\,/" config.example.json
|
||||
fi
|
||||
sed -i -e "s/\"relaunch_on_error.*$/\"relaunch_on_error\": true\,/" config.example.json
|
||||
sed -i -e "s/\"threads_num.*$/\"threads_num\": 0\,/" config.example.json
|
||||
sed -i -e "s/\"use_brotli.*$/\"use_brotli\": true\,/" config.example.json
|
||||
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
|
||||
sed -i -e "s/\"enable_request_stream.*$/\"enable_request_stream\": true\,/" config.example.json
|
||||
update_config_line "enable_request_stream" "true" config.example.json
|
||||
else
|
||||
sed -i -e "s/\"enable_request_stream.*$/\"enable_request_stream\": false\,/" config.example.json
|
||||
update_config_line "enable_request_stream" "false" config.example.json
|
||||
fi
|
||||
|
||||
if [ ! -f "integration_test_client" ]; then
|
||||
if [ ! -f "$integration_test_client_exec" ]; then
|
||||
echo "Build failed"
|
||||
exit -1
|
||||
fi
|
||||
if [ ! -f "integration_test_server" ]; then
|
||||
if [ ! -f "$integration_test_server_exec" ]; then
|
||||
echo "Build failed"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
killall -9 integration_test_server
|
||||
./integration_test_server &
|
||||
cleanup_integration_test_server
|
||||
|
||||
sleep 4
|
||||
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 -s
|
||||
"$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
|
||||
|
||||
killall -9 integration_test_server
|
||||
cleanup_integration_test_server
|
||||
popd
|
||||
}
|
||||
|
||||
@@ -70,7 +171,7 @@ function do_integration_test()
|
||||
function do_drogon_ctl_test()
|
||||
{
|
||||
echo "Testing drogon_ctl"
|
||||
pushd $test_root
|
||||
pushd "$test_root"
|
||||
rm -rf drogon_test
|
||||
|
||||
${drogon_ctl_exec} create project drogon_test
|
||||
@@ -122,22 +223,23 @@ function do_drogon_ctl_test()
|
||||
make_flags=''
|
||||
cmake_gen=''
|
||||
parallel=1
|
||||
cpu_count=$(get_cpu_count)
|
||||
|
||||
# simulate ninja's parallelism
|
||||
case $(nproc) in
|
||||
case $cpu_count in
|
||||
1)
|
||||
parallel=$(($(nproc) + 1))
|
||||
parallel=$((cpu_count + 1))
|
||||
;;
|
||||
2)
|
||||
parallel=$(($(nproc) + 1))
|
||||
parallel=$((cpu_count + 1))
|
||||
;;
|
||||
*)
|
||||
parallel=$(($(nproc) + 2))
|
||||
parallel=$((cpu_count + 2))
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "X$os" = "Xlinux" ]; then
|
||||
if [ -f /bin/ninja ]; then
|
||||
if command -v ninja > /dev/null 2>&1; then
|
||||
cmake_gen='-G Ninja'
|
||||
else
|
||||
make_flags="$make_flags -j$parallel"
|
||||
@@ -162,11 +264,11 @@ function do_drogon_ctl_test()
|
||||
exit -1
|
||||
fi
|
||||
|
||||
if [ "X$os" = "Xlinux" ]; then
|
||||
if [ ! -f "drogon_test" ]; then
|
||||
echo "Failed to build drogon_test"
|
||||
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"
|
||||
@@ -183,7 +285,7 @@ function do_drogon_ctl_test()
|
||||
function do_unittest()
|
||||
{
|
||||
echo "Unit testing"
|
||||
pushd $src_dir/build
|
||||
pushd "$src_dir/build"
|
||||
|
||||
ctest . --output-on-failure
|
||||
if [ $? -ne 0 ]; then
|
||||
@@ -195,7 +297,7 @@ function do_unittest()
|
||||
|
||||
function do_db_test()
|
||||
{
|
||||
pushd $src_dir/build
|
||||
pushd "$src_dir/build"
|
||||
if [ -f "./orm_lib/tests/db_test" ]; then
|
||||
echo "Test database"
|
||||
./orm_lib/tests/db_test -s
|
||||
@@ -246,9 +348,9 @@ function do_db_test()
|
||||
fi
|
||||
}
|
||||
|
||||
if ! drogon_ctl -v > /dev/null 2>&1
|
||||
if [ ! -f "$drogon_ctl_exec" ]
|
||||
then
|
||||
echo "Warning: No drogon_ctl, skip integration test and drogon_ctl test"
|
||||
echo "Warning: No built drogon_ctl, skip integration test and drogon_ctl test"
|
||||
else
|
||||
do_integration_test
|
||||
do_integration_test stream_mode
|
||||
|
||||
Reference in New Issue
Block a user