mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 00:17:25 +08:00
[CI] Add nightly workflow for golang_router tests and improve log handling (#6608)
* [CI] Add nightly workflow for Golang router tests * [CI] Improve pytest script stability and log handling
This commit is contained in:
+59
-8
@@ -13,11 +13,11 @@ failed_tests_file="failed_tests.log"
|
||||
|
||||
|
||||
##################################
|
||||
# 执行 pytest,每个文件单独跑
|
||||
# 使用 pytest 的 --collect-only 输出,并从每行中提取真正的测试文件路径(形如 tests/.../test_*.py)。
|
||||
# 注意:pytest 在收集失败时会输出形如 "ERROR tests/xxx/test_xxx.py::test_xxx ..." 的行,
|
||||
# 为了避免把前缀 "ERROR"/"FAILED"/"collecting" 等误当成文件名,这里只保留行中出现的
|
||||
# "tests/.../test_*.py" 这一段,其他前后内容直接丢弃。
|
||||
# Run pytest, one file at a time
|
||||
# Use pytest's --collect-only output to extract the actual test file paths (e.g., tests/.../test_*.py).
|
||||
# Note: pytest may output lines like "ERROR tests/xxx/test_xxx.py::test_xxx ..." on collection failure,
|
||||
# to avoid treating prefixes like "ERROR"/"FAILED"/"collecting" as filenames,
|
||||
# we only keep the "tests/.../test_*.py" portion and discard everything else.
|
||||
TEST_FILES=$(
|
||||
python -m pytest --collect-only -q -c "${PYTEST_INI}" "${tests_path}" --rootdir="${run_path}" --disable-warnings 2>&1 \
|
||||
| grep -E 'tests/.+\/test_.*\.py' \
|
||||
@@ -29,30 +29,81 @@ TEST_FILES=$(
|
||||
failed_pytest=0
|
||||
success_pytest=0
|
||||
|
||||
# nullglob: if no match, the pattern expands to nothing
|
||||
shopt -s nullglob
|
||||
|
||||
for file in $TEST_FILES; do
|
||||
echo "Running pytest file: $file"
|
||||
# Clean up previous logs
|
||||
rm -rf "${run_path}"/log* || true
|
||||
rm -rf "${run_path}"/*.log || true
|
||||
|
||||
# Run pytest with coverage for the current file
|
||||
python -m coverage run -m pytest -c ${PYTEST_INI} "$file" -vv -s
|
||||
status=$?
|
||||
if [ "$status" -ne 0 ]; then
|
||||
echo "$file" >> "$failed_tests_file"
|
||||
failed_pytest=$((failed_pytest+1))
|
||||
|
||||
echo ""
|
||||
echo "==================== Dumping Logs ===================="
|
||||
|
||||
for log_dir in "${run_path}"/log*; do
|
||||
if [ -d "${log_dir}" ]; then
|
||||
echo
|
||||
echo ">>>> Processing log directory: ${log_dir}"
|
||||
|
||||
# print all workerlog.0
|
||||
worker_logs=("${log_dir}"/workerlog.0)
|
||||
if [ "${#worker_logs[@]}" -gt 0 ]; then
|
||||
for worker_log in "${worker_logs[@]}"; do
|
||||
if [ -f "${worker_log}" ]; then
|
||||
echo "---------------- ${worker_log} (last 100 lines) ----------------"
|
||||
tail -n 100 "${worker_log}" || true
|
||||
echo "---------------------------------------------------------------"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No workerlog.0 found in ${log_dir}"
|
||||
fi
|
||||
|
||||
echo ">>> grep error in ${log_dir}"
|
||||
grep -Rni --color=auto "error" "${log_dir}" || true
|
||||
fi
|
||||
done
|
||||
|
||||
# print all server logs
|
||||
server_logs=("${run_path}"/*.log)
|
||||
if [ "${#server_logs[@]}" -gt 0 ]; then
|
||||
for server_log in "${server_logs[@]}"; do
|
||||
if [ -f "${server_log}" ]; then
|
||||
echo
|
||||
echo "---------------- ${server_log} (last 100 lines) ----------------"
|
||||
tail -n 100 "${server_log}" || true
|
||||
echo "---------------------------------------------------------------"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No *.log files found"
|
||||
fi
|
||||
|
||||
echo "======================================================"
|
||||
else
|
||||
success_pytest=$((success_pytest+1))
|
||||
fi
|
||||
ps -ef | grep "${FD_CACHE_QUEUE_PORT}" | grep -v grep | awk '{print $2}' | xargs -r kill -9
|
||||
ps -ef | grep "${FD_ENGINE_QUEUE_PORT}" | grep -v grep | awk '{print $2}' | xargs -r kill -9
|
||||
done
|
||||
shopt -u nullglob
|
||||
|
||||
##################################
|
||||
# 汇总结果
|
||||
# Summary
|
||||
##################################
|
||||
echo "===================================="
|
||||
echo "Pytest total: $((failed_pytest + success_pytest))"
|
||||
echo "Pytest successful: $success_pytest"
|
||||
echo "Pytest failed: $failed_pytest"
|
||||
|
||||
echo "Special tests total: ${#special_tests[@]}"
|
||||
echo "Special tests successful: $success_special"
|
||||
|
||||
if [ "$failed_pytest" -ne 0 ]; then
|
||||
echo "Failed test cases are listed in $failed_tests_file"
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||
|
||||
GOLANG_ROUTER_CASES_DIR="${REPO_ROOT}/tests/e2e/golang_router"
|
||||
FAILED_CASE_FILE="${REPO_ROOT}/failed_cases.txt"
|
||||
|
||||
FAILED_COUNT=0
|
||||
|
||||
rm -f "${FAILED_CASE_FILE}"
|
||||
|
||||
shopt -s nullglob
|
||||
test_files=("${GOLANG_ROUTER_CASES_DIR}"/test_*.py)
|
||||
|
||||
if [ "${#test_files[@]}" -eq 0 ]; then
|
||||
echo "ERROR: No test files found under: ${GOLANG_ROUTER_CASES_DIR}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for test_file in "${test_files[@]}"; do
|
||||
echo "------------------------------------------------------------"
|
||||
echo "Running pytest: ${test_file}"
|
||||
echo "------------------------------------------------------------"
|
||||
# Clean up previous logs
|
||||
rm -rf "${REPO_ROOT}"/log* || true
|
||||
rm -rf "${REPO_ROOT}"/*.log || true
|
||||
|
||||
if ! python -m pytest -sv --tb=short "${test_file}"; then
|
||||
echo "Pytest failed for: ${test_file}"
|
||||
echo "${test_file}" >> "${FAILED_CASE_FILE}"
|
||||
FAILED_COUNT=$((FAILED_COUNT + 1))
|
||||
|
||||
echo ""
|
||||
echo "==================== Dumping Logs ===================="
|
||||
|
||||
for log_dir in "${REPO_ROOT}"/log*; do
|
||||
if [ -d "${log_dir}" ]; then
|
||||
echo
|
||||
echo ">>>> Processing log directory: ${log_dir}"
|
||||
|
||||
# print all workerlog.0
|
||||
worker_logs=("${log_dir}"/workerlog.0)
|
||||
if [ "${#worker_logs[@]}" -gt 0 ]; then
|
||||
for worker_log in "${worker_logs[@]}"; do
|
||||
if [ -f "${worker_log}" ]; then
|
||||
echo "---------------- ${worker_log} (last 100 lines) ----------------"
|
||||
tail -n 100 "${worker_log}" || true
|
||||
echo "---------------------------------------------------------------"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No workerlog.0 found in ${log_dir}"
|
||||
fi
|
||||
|
||||
echo ">>> grep error in ${log_dir}"
|
||||
grep -Rni --color=auto "error" "${log_dir}" || true
|
||||
fi
|
||||
done
|
||||
|
||||
# print all server logs
|
||||
server_logs=("${REPO_ROOT}"/*.log)
|
||||
if [ "${#server_logs[@]}" -gt 0 ]; then
|
||||
for server_log in "${server_logs[@]}"; do
|
||||
if [ -f "${server_log}" ]; then
|
||||
echo
|
||||
echo "---------------- ${server_log} (last 100 lines) ----------------"
|
||||
tail -n 100 "${server_log}" || true
|
||||
echo "---------------------------------------------------------------"
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No *.log files found"
|
||||
fi
|
||||
|
||||
echo "======================================================"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
|
||||
shopt -u nullglob
|
||||
|
||||
if [ "${FAILED_COUNT}" -ne 0 ]; then
|
||||
echo "${FAILED_COUNT} test file(s) failed:"
|
||||
cat "${FAILED_CASE_FILE}"
|
||||
exit 1
|
||||
else
|
||||
echo "All golang_router end-to-end tests passed"
|
||||
exit 0
|
||||
fi
|
||||
@@ -22,26 +22,42 @@ for test_file in "${test_files[@]}"; do
|
||||
echo "------------------------------------------------------------"
|
||||
echo "Running pytest: ${test_file}"
|
||||
echo "------------------------------------------------------------"
|
||||
# Clean up previous logs
|
||||
rm -rf "${REPO_ROOT}"/log* || true
|
||||
rm -rf "${REPO_ROOT}"/*.log || true
|
||||
|
||||
if ! python -m pytest -sv --tb=short "${test_file}"; then
|
||||
echo "Pytest failed for: ${test_file}"
|
||||
echo "${test_file}" >> "${FAILED_CASE_FILE}"
|
||||
FAILED_COUNT=$((FAILED_COUNT + 1))
|
||||
|
||||
echo ""
|
||||
echo "==================== Dumping Logs ===================="
|
||||
|
||||
if [ -d "${REPO_ROOT}/log" ]; then
|
||||
echo ">>> grep error in ${REPO_ROOT}/log/"
|
||||
grep -Rni --color=auto "error" "${REPO_ROOT}/log/" || true
|
||||
else
|
||||
echo "${REPO_ROOT}/log directory not found"
|
||||
fi
|
||||
|
||||
if [ -f "${REPO_ROOT}/log/log_0/workerlog.0" ]; then
|
||||
echo "---------------- workerlog.0 (last 200 lines) -------------"
|
||||
tail -n 200 "${REPO_ROOT}/log/log_0/workerlog.0"
|
||||
echo "---------------- workerlog.0 (last 100 lines) -------------"
|
||||
tail -n 100 "${REPO_ROOT}/log/log_0/workerlog.0"
|
||||
echo "------------------------------------------------------------"
|
||||
fi
|
||||
|
||||
if [ -f "${REPO_ROOT}/server.log" ]; then
|
||||
echo "---------------- server.log (last 200 lines) ---------------"
|
||||
tail -n 200 "${REPO_ROOT}/server.log"
|
||||
echo "---------------- server.log (last 100 lines) ---------------"
|
||||
tail -n 100 "${REPO_ROOT}/server.log"
|
||||
echo "------------------------------------------------------------"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
|
||||
shopt -u nullglob
|
||||
|
||||
if [ "${FAILED_COUNT}" -ne 0 ]; then
|
||||
|
||||
Reference in New Issue
Block a user