[CI]【Hackathon 9th Sprint No.40】功能模块 fastdeploy/entrypoints/openai/api_server.py 单测补充 (#5567)

* Add tests for openai api_server coverage

* update

* Update tests for openai api_server

* fix bugs

* test: disable some api_server lifespan/controller tests for local env

* Format test_api_server with black

* update

* update

* test: narrow envs patch in api_server tests to avoid side effects

* fix: separate MagicMock creation to avoid missing req argument

* fix: patch TRACES_ENABLE env var in api_server tests

* fix: use os.environ patch for TRACES_ENABLE

* test: use fake fastdeploy.envs in api_server tests

* test: pass fake Request into chat/completion routes

* test: increase coverage for tracing and scheduler control

* fix: set dynamic_load_weight in tracing headers test

* ci: add retry and validation for FastDeploy.tar.gz download

* ci: fix indentation in _base_test.yml

* refactor: simplify test_api_server.py (807->480 lines, ~40% reduction)

* fix: restore missing args attributes (revision, etc.) in _build_args

* fix: patch sys.argv to prevent SystemExit: 2 in api_server tests

* improve coverage

* Remove docstring from test_api_server.py

Removed unnecessary docstring from test_api_server.py

---------

Co-authored-by: CSWYF3634076 <wangyafeng@baidu.com>
This commit is contained in:
kesmeey
2025-12-23 18:06:43 +08:00
committed by GitHub
parent e9f5397bc9
commit f15edbb6ef
2 changed files with 758 additions and 22 deletions

View File

@@ -39,29 +39,54 @@ jobs:
docker_image: ${{ inputs.DOCKER_IMAGE }}
fd_archive_url: ${{ inputs.FASTDEPLOY_ARCHIVE_URL }}
run: |
set -x
REPO="https://github.com/${{ github.repository }}.git"
FULL_REPO="${{ github.repository }}"
REPO_NAME="${FULL_REPO##*/}"
BASE_BRANCH="${{ github.base_ref }}"
docker pull ${docker_image}
# Clean the repository directory before starting
docker run --rm --net=host -v $(pwd):/workspace -w /workspace \
-e "REPO_NAME=${REPO_NAME}" \
${docker_image} /bin/bash -c '
if [ -d ${REPO_NAME} ]; then
echo "Directory ${REPO_NAME} exists, removing it..."
rm -rf ${REPO_NAME}*
fi
'
set -x
REPO="https://github.com/${{ github.repository }}.git"
FULL_REPO="${{ github.repository }}"
REPO_NAME="${FULL_REPO##*/}"
BASE_BRANCH="${{ github.base_ref }}"
docker pull ${docker_image}
# Clean the repository directory before starting
docker run --rm --net=host -v $(pwd):/workspace -w /workspace \
-e "REPO_NAME=${REPO_NAME}" \
${docker_image} /bin/bash -c '
if [ -d ${REPO_NAME} ]; then
echo "Directory ${REPO_NAME} exists, removing it..."
rm -rf ${REPO_NAME}*
fi
'
wget -q --no-proxy ${fd_archive_url}
tar -xf FastDeploy.tar.gz
rm -rf FastDeploy.tar.gz
cd FastDeploy
git config --global user.name "FastDeployCI"
git config --global user.email "fastdeploy_ci@example.com"
git log -n 3 --oneline
# Download with retry and validation
MAX_RETRIES=3
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if wget -q --no-proxy ${fd_archive_url} && [ -f FastDeploy.tar.gz ] && [ -s FastDeploy.tar.gz ]; then
echo "Download successful, file size: $(stat -c%s FastDeploy.tar.gz) bytes"
break
else
RETRY_COUNT=$((RETRY_COUNT + 1))
echo "Download failed or file is empty, retry $RETRY_COUNT/$MAX_RETRIES..."
rm -f FastDeploy.tar.gz
sleep 2
fi
done
if [ ! -f FastDeploy.tar.gz ] || [ ! -s FastDeploy.tar.gz ]; then
echo "ERROR: Failed to download FastDeploy.tar.gz after $MAX_RETRIES attempts"
exit 1
fi
# Verify tar.gz integrity before extraction
if ! tar -tzf FastDeploy.tar.gz > /dev/null 2>&1; then
echo "ERROR: FastDeploy.tar.gz is corrupted or incomplete"
exit 1
fi
tar -xf FastDeploy.tar.gz
rm -rf FastDeploy.tar.gz
cd FastDeploy
git config --global user.name "FastDeployCI"
git config --global user.email "fastdeploy_ci@example.com"
git log -n 3 --oneline
- name: Run FastDeploy Base Tests
shell: bash