be5d5ede90
refactor: 重构后端查询逻辑和API响应处理 fix: 修复用户角色更新和文件上传问题 test: 添加前端性能测试脚本和E2E测试用例 chore: 更新依赖版本和配置文件 docs: 添加环境检查脚本和测试文档 style: 统一表格标签样式和路由命名 perf: 优化前端页面加载速度和响应时间
124 lines
3.6 KiB
Bash
124 lines
3.6 KiB
Bash
#!/bin/bash
|
|
|
|
echo "========================================="
|
|
echo "性能测试执行脚本"
|
|
echo "========================================="
|
|
|
|
BASE_URL=${1:-"http://localhost:8084"}
|
|
FRONTEND_URL=${2:-"http://localhost:3001"}
|
|
|
|
echo "后端API URL: $BASE_URL"
|
|
echo "前端URL: $FRONTEND_URL"
|
|
echo ""
|
|
|
|
# 检查k6是否安装
|
|
if ! command -v k6 &> /dev/null; then
|
|
echo "❌ k6未安装,正在安装..."
|
|
|
|
# 检测操作系统
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
# macOS
|
|
if ! command -v brew &> /dev/null; then
|
|
echo "❌ Homebrew未安装,请先安装Homebrew"
|
|
exit 1
|
|
fi
|
|
brew install k6
|
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
# Linux
|
|
sudo gpg -k
|
|
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
|
|
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
|
|
sudo apt-get update
|
|
sudo apt-get install k6
|
|
else
|
|
echo "❌ 不支持的操作系统: $OSTYPE"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ k6安装完成"
|
|
else
|
|
echo "✅ k6已安装"
|
|
fi
|
|
|
|
echo ""
|
|
echo "========================================="
|
|
echo "开始执行性能测试"
|
|
echo "========================================="
|
|
|
|
# 创建测试结果目录
|
|
mkdir -p test-results/performance
|
|
|
|
# 1. API性能测试
|
|
echo ""
|
|
echo "1️⃣ 执行API性能测试..."
|
|
BASE_URL=$BASE_URL k6 run tests/performance/api-performance-test.js \
|
|
--out json=test-results/performance/api-results.json \
|
|
--out json=test-results/performance/api-results-summary.json
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ API性能测试完成"
|
|
else
|
|
echo "❌ API性能测试失败"
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
# 2. 前端性能测试
|
|
echo ""
|
|
echo "2️⃣ 执行前端性能测试..."
|
|
BASE_URL=$FRONTEND_URL k6 run tests/performance/frontend-performance-test.js \
|
|
--out json=test-results/performance/frontend-results.json \
|
|
--out json=test-results/performance/frontend-results-summary.json
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ 前端性能测试完成"
|
|
else
|
|
echo "❌ 前端性能测试失败"
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
# 3. 数据库性能测试
|
|
echo ""
|
|
echo "3️⃣ 执行数据库性能测试..."
|
|
BASE_URL=$BASE_URL k6 run tests/performance/database-performance-test.js \
|
|
--out json=test-results/performance/database-results.json \
|
|
--out json=test-results/performance/database-results-summary.json
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ 数据库性能测试完成"
|
|
else
|
|
echo "❌ 数据库性能测试失败"
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
# 4. 并发压力测试
|
|
echo ""
|
|
echo "4️⃣ 执行并发压力测试..."
|
|
BASE_URL=$BASE_URL k6 run tests/performance/concurrent-load-test.js \
|
|
--out json=test-results/performance/concurrent-results.json \
|
|
--out json=test-results/performance/concurrent-results-summary.json
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ 并发压力测试完成"
|
|
else
|
|
echo "❌ 并发压力测试失败"
|
|
fi
|
|
|
|
echo ""
|
|
echo "========================================="
|
|
echo "性能测试执行完成"
|
|
echo "========================================="
|
|
echo ""
|
|
echo "测试结果保存在: test-results/performance/"
|
|
echo ""
|
|
echo "结果文件列表:"
|
|
ls -lh test-results/performance/
|
|
|
|
echo ""
|
|
echo "性能测试摘要:"
|
|
echo "- API性能测试: test-results/performance/api-results-summary.json"
|
|
echo "- 前端性能测试: test-results/performance/frontend-results-summary.json"
|
|
echo "- 数据库性能测试: test-results/performance/database-results-summary.json"
|
|
echo "- 并发压力测试: test-results/performance/concurrent-results-summary.json" |