Files
momentry_core/scripts/test_release_v1.3.3.sh
Accusys dc6081fcaf release: v1.3.4 - File Metadata Display & Queue Monitoring
Phase 1 Features:
- Add file_size and modified_time to videos table
- Display file metadata in /api/v1/files
- Queue monitoring script (auto-cleanup stuck commands)

Improvements:
- 188 files updated with metadata
- Queue monitoring runs every 5 minutes
- Auto-reset stuck commands (>1 hour)
- Auto-cleanup orphan commands

Documentation:
- Pipeline worker architecture analysis
- Refactor plan (Phase 2)
- Release checklist and test reports

Tested:
- All P0 tests passed
- API response time < 100ms
- Data coverage 99.5%
2026-10-12 23:29:47 +08:00

171 lines
5.8 KiB
Bash
Executable File

#!/bin/bash
# Release v1.3.3 自动化测试脚本
set -e
# 颜色定义
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 测试计数器
TOTAL_TESTS=0
PASSED_TESTS=0
FAILED_TESTS=0
# 日志函数
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# 测试函数
run_test() {
local test_name=$1
local test_command=$2
TOTAL_TESTS=$((TOTAL_TESTS + 1))
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "测试 $TOTAL_TESTS: $test_name"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if eval "$test_command"; then
log_info "✅ $test_name 通过"
PASSED_TESTS=$((PASSED_TESTS + 1))
return 0
else
log_error "❌ $test_name 失败"
FAILED_TESTS=$((FAILED_TESTS + 1))
return 1
fi
}
# 主测试流程
main() {
echo "╔════════════════════════════════════════╗"
echo "║ Release v1.3.3 自动化测试 ║"
echo "║ 测试时间: $(date '+%Y-%m-%d %H:%M:%S') ║"
echo "╚════════════════════════════════════════╝"
echo ""
# TC-01: 数据库字段检查
run_test "TC-01: 数据库字段存在性" "
/opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d momentry -c '\d videos' | grep -E 'file_size|modified_time' > /dev/null
"
# TC-01: 数据覆盖率检查
run_test "TC-01: 数据覆盖率检查" "
COUNT=\$(/opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d momentry -t -c 'SELECT COUNT(*) FROM videos WHERE file_size IS NOT NULL;' | tr -d ' ')
if [ \"\$COUNT\" -ge 100 ]; then
log_info \"数据量: \$COUNT 个文件\"
exit 0
else
log_error \"数据量不足: \$COUNT < 100\"
exit 1
fi
"
# TC-02: 队列监控服务
run_test "TC-02: 队列监控服务运行" "
launchctl list | grep command_monitor > /dev/null
"
# TC-02: 监控日志检查
run_test "TC-02: 监控日志存在" "
test -f /Users/accusys/momentry_core/logs/command_monitor.log
"
# TC-06: Worker 进程
run_test "TC-06: Pipeline Worker 进程运行" "
ps aux | grep '[p]ipeline_worker' > /dev/null
"
# TC-06: Worker launchd 状态
run_test "TC-06: Worker launchd 状态正常" "
launchctl print gui/\$(id -u)/com.momentry.pipeline_worker 2>&1 | grep 'state = running' > /dev/null
"
# TC-07: 数据库索引
run_test "TC-07: 数据库索引创建" "
/opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d momentry -c '\di' | grep -E 'idx_videos_file_size|idx_videos_modified_time' > /dev/null
"
# TC-05: API 文件列表
run_test "TC-05: API 文件列表响应" "
curl -s -f 'http://localhost:3002/api/v1/files?page=1&page_size=1' > /dev/null
"
# TC-05: API 返回 file_size
run_test "TC-05: API 返回 file_size 字段" "
curl -s 'http://localhost:3002/api/v1/files?page=1&page_size=1' | jq '.data[0].file_size' > /dev/null
"
# TC-05: API 返回 modified_time
run_test "TC-05: API 返回 modified_time 字段" "
curl -s 'http://localhost:3002/api/v1/files?page=1&page_size=1' | jq '.data[0].modified_time' > /dev/null
"
# TC-08: API 性能测试
run_test "TC-08: API 响应时间 < 500ms" "
TIME=\$( { time curl -s 'http://localhost:3002/api/v1/files?page=1&page_size=20' > /dev/null; } 2>&1 | grep real | awk '{print \$2}' | sed 's/[ms]/ /g' | awk '{print \$1}')
if [ \$(echo \"\$TIME < 0.5\" | bc) -eq 1 ]; then
log_info \"响应时间: \${TIME}s\"
exit 0
else
log_error \"响应时间过长: \${TIME}s\"
exit 1
fi
"
# TC-06: 队列状态检查
run_test "TC-06: 队列无 stuck 命令" "
STUCK=\$(/opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d momentry -t -c \"SELECT COUNT(*) FROM command_queue WHERE status = 'processing' AND processing_started_at < NOW() - INTERVAL '1 hour';\" | tr -d ' ')
if [ \"\$STUCK\" -eq 0 ]; then
log_info \"无 stuck 命令\"
exit 0
else
log_error \"发现 \$STUCK 个 stuck 命令\"
exit 1
fi
"
# TC-01: 数据样本验证
run_test "TC-01: 数据样本格式正确" "
/opt/homebrew/Cellar/libpq/18.4/bin/psql -U accusys -d momentry -t -c \"SELECT file_size, modified_time FROM videos WHERE file_size IS NOT NULL LIMIT 1;\" | grep -E '[0-9]+.*[0-9]{4}-[0-9]{2}-[0-9]{2}' > /dev/null
"
# 测试汇总
echo ""
echo "╔════════════════════════════════════════╗"
echo "║ 测试结果汇总 ║"
echo "╚════════════════════════════════════════╝"
echo ""
echo "总测试数: $TOTAL_TESTS"
echo -e "通过: ${GREEN}$PASSED_TESTS${NC}"
echo -e "失败: ${RED}$FAILED_TESTS${NC}"
echo ""
if [ $FAILED_TESTS -eq 0 ]; then
echo -e "${GREEN}✅ 所有测试通过!${NC}"
echo ""
echo "Release v1.3.3 测试通过,可以交付。"
exit 0
else
echo -e "${RED}❌ 有 $FAILED_TESTS 个测试失败${NC}"
echo ""
echo "请修复失败项后再重新测试。"
exit 1
fi
}
# 执行主函数
main