test(perf): 添加API性能基线测试,核心接口响应时间阈值监控 #190

Merged
xiaoxia merged 1 commits from feat/add-performance-baseline into develop 2026-07-09 11:04:16 +08:00
Owner

API 性能基线测试

为核心 API 接口添加性能基线测试,确保接口响应时间在合理范围内。

新增文件

  • tests/integration/conftest.py - 性能测试基础设施

    • 性能阈值配置(core: 500ms / normal: 1000ms / heavy: 3000ms)
    • perf_assert fixture,支持多次采样 + 中位数判断
    • performance / perf_core / perf_normal / perf_heavy pytest marker
    • 通过 SKIP_PERF_TESTS=1 环境变量跳过性能测试
    • 容忍度机制:允许一定比例的请求超标(避免CI偶发波动)
  • tests/integration/test_api_performance.py - 13 个性能测试用例

    • 核心接口(500ms):登录、获取当前用户、项目列表、素材列表、生成任务列表、订阅信息(6个)
    • 普通接口(1000ms):创建项目、模板列表、剪辑计划列表(3个)
    • 重操作(3000ms):获取上传签名、创建生成任务、去重上传(3个)
    • 汇总报告测试(1个)

修改文件

  • .gitea/workflows/ci-cd.yml - 在集成测试后添加性能测试步骤

    • continue-on-error: true,失败不阻塞主流水线
    • 输出结构化性能报告(PERF_STATS / PERF_RESULT 格式)
  • tests/e2e/api_smoke_test.sh - 冒烟测试脚本增加响应时间检查

    • 新增 PERF_CHECK_ENABLED、PERF_WARN_THRESHOLD_MS、PERF_FAIL_THRESHOLD_MS 环境变量
    • 新增 perf_check() 和 curl_timed() 工具函数

跳过方式

# 方式1:环境变量
SKIP_PERF_TESTS=1 pytest tests/integration/test_api_performance.py -v

# 方式2:pytest marker
pytest tests/integration/test_api_performance.py -m "not performance"

性能报告格式

每个接口输出 PERF_RESULT 行,包含:

  • 状态(PASS/FAIL)
  • 接口名称
  • 中位数响应时间 + 阈值
  • min/max/mean
  • HTTP 状态码

CI 中通过 grep 解析即可快速统计。

## API 性能基线测试 为核心 API 接口添加性能基线测试,确保接口响应时间在合理范围内。 ### 新增文件 - **tests/integration/conftest.py** - 性能测试基础设施 - 性能阈值配置(core: 500ms / normal: 1000ms / heavy: 3000ms) - perf_assert fixture,支持多次采样 + 中位数判断 - performance / perf_core / perf_normal / perf_heavy pytest marker - 通过 SKIP_PERF_TESTS=1 环境变量跳过性能测试 - 容忍度机制:允许一定比例的请求超标(避免CI偶发波动) - **tests/integration/test_api_performance.py** - 13 个性能测试用例 - 核心接口(500ms):登录、获取当前用户、项目列表、素材列表、生成任务列表、订阅信息(6个) - 普通接口(1000ms):创建项目、模板列表、剪辑计划列表(3个) - 重操作(3000ms):获取上传签名、创建生成任务、去重上传(3个) - 汇总报告测试(1个) ### 修改文件 - **.gitea/workflows/ci-cd.yml** - 在集成测试后添加性能测试步骤 - continue-on-error: true,失败不阻塞主流水线 - 输出结构化性能报告(PERF_STATS / PERF_RESULT 格式) - **tests/e2e/api_smoke_test.sh** - 冒烟测试脚本增加响应时间检查 - 新增 PERF_CHECK_ENABLED、PERF_WARN_THRESHOLD_MS、PERF_FAIL_THRESHOLD_MS 环境变量 - 新增 perf_check() 和 curl_timed() 工具函数 ### 跳过方式 ```bash # 方式1:环境变量 SKIP_PERF_TESTS=1 pytest tests/integration/test_api_performance.py -v # 方式2:pytest marker pytest tests/integration/test_api_performance.py -m "not performance" ``` ### 性能报告格式 每个接口输出 PERF_RESULT 行,包含: - 状态(PASS/FAIL) - 接口名称 - 中位数响应时间 + 阈值 - min/max/mean - HTTP 状态码 CI 中通过 grep 解析即可快速统计。
xiaoxia added 1 commit 2026-07-09 10:48:04 +08:00
test(perf): 添加API性能基线测试,核心接口响应时间阈值监控
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 2h6m24s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 2h6m24s
9add9bda94
xiaoxia merged commit 7aabc3d09b into develop 2026-07-09 11:04:16 +08:00
Sign in to join this conversation.