## v0.9.20260325_144654 ### Features - API Key Authentication System - Job Worker System - V2 Backup Versioning ### Bug Fixes - get_processor_results_by_job column mapping Co-authored-by: OpenCode
26 KiB
26 KiB
Momentry 系統測試與驗證計劃
計劃階段 - 僅供討論,尚未執行 建立時間: 2026-03-23 目標: 安裝後測試、跑分、燒機
目錄
一、跑分機制
1.1 目的
在系統安裝完成後,評估以下效能指標:
| 類別 | 項目 | 指標 |
|---|---|---|
| 儲存 | 磁碟讀寫速度 | MB/s |
| 網路 | 吞吐量、延遲 | Mbps, ms |
| 資料庫 | 查詢效能 | QPS, 延遲 |
| 影片處理 | 處理速度 | 幀/秒 |
| 向量搜尋 | 搜尋效能 | QPS, 延遲 |
| RAG | 端對端效能 | 回應時間 |
1.2 跑分項目
1.2.1 硬體效能測試
#!/bin/bash
# benchmark/hardware_benchmark.sh
# 1. 磁碟效能
disk_benchmark() {
echo "=== 磁碟效能測試 ==="
# 順序寫入
dd if=/dev/zero of=/Volumes/Momentry/test/write.test bs=1M count=1024 conv=fdatasync
# 順序讀取
dd if=/Volumes/Momentry/test/write.test of=/dev/null bs=1M
# 隨機讀寫 (使用 fio)
fio --name=randread --ioengine=io_uring --rw=randread \
--bs=4k --size=1G --numjobs=4 --directory=/Volumes/Momentry/test
fio --name=randwrite --ioengine=io_uring --rw=randwrite \
--bs=4k --size=1G --numjobs=4 --directory=/Volumes/Momentry/test
}
# 2. 記憶體效能
memory_benchmark() {
echo "=== 記憶體效能測試 ==="
# 記憶體頻寬
mlc --idle_latency
mlc --peak_injection_bandwidth
}
# 3. 網路效能
network_benchmark() {
echo "=== 網路效能測試 ==="
# 內網測試
iperf3 -c 10.10.10.1 -t 30 -P 4
# Thunderbolt 網路
iperf3 -c <tbt_host> -t 30 -P 4
}
# 4. CPU 效能
cpu_benchmark() {
echo "=== CPU 效能測試 ==="
# Geekbench 風格測試
sysbench cpu --cpu-max-prime=20000 run
# 多核心測試
sysbench cpu --cpu-max-prime=20000 --threads=$(sysctl -n hw.ncpu) run
}
1.2.2 資料庫效能測試
#!/bin/bash
# benchmark/database_benchmark.sh
# PostgreSQL 效能
postgresql_benchmark() {
echo "=== PostgreSQL 效能測試 ==="
# 初始化測試資料
pgbench -i -s 100 momentry
# 讀取測試
pgbench -c 10 -j 4 -S -T 60 momentry
# 寫入測試
pgbench -c 10 -j 4 -T 60 momentry
# 混合測試
pgbench -c 10 -j 4 -b select,update,insert -T 60 momentry
}
# MongoDB 效能
mongodb_benchmark() {
echo "=== MongoDB 效能測試 ==="
# 插入測試
mongosh --eval '
use benchmark;
for (let i = 0; i < 100000; i++) {
db.test.insertOne({index: i, data: "test data " + i});
}
'
# 查詢測試
mongosh --eval '
use benchmark;
db.test.find({index: {$gt: 50000}}).explain("executionStats");
'
}
# Redis 效能
redis_benchmark() {
echo "=== Redis 效能測試 ==="
redis-benchmark -t set,get -n 100000 -c 50
redis-benchmark -t lpush,rpop -n 100000 -c 50
redis-benchmark -t hset,hget -n 100000 -c 50
}
# Qdrant 效能
qdrant_benchmark() {
echo "=== Qdrant 效能測試 ==="
# 向量搜尋測試
python3 scripts/benchmark/qdrant_benchmark.py \
--collections momentry \
--queries 1000 \
--vectors 100000
}
1.2.3 影片處理效能
#!/bin/bash
# benchmark/video_benchmark.sh
# 影片處理時間測試
video_processing_benchmark() {
local VIDEO="/Volumes/Momentry/Data/Test/videos/sample_1080p.mp4"
echo "=== 影片處理效能測試 ==="
# ASR (語音識別)
time cargo run --bin momentry -- process "$VIDEO" --modules asr
# YOLO (物件偵測)
time cargo run --bin momentry -- process "$VIDEO" --modules yolo
# OCR (文字識別)
time cargo run --bin momentry -- process "$VIDEO" --modules ocr
# Face (人臉識別)
time cargo run --bin momentry -- process "$VIDEO" --modules face
# 完整處理
time cargo run --bin momentry -- process "$VIDEO" --all
}
# 幀率統計
fps_benchmark() {
echo "=== 處理幀率 ==="
# 計算每秒處理幀數
local START=$(date +%s.%N)
local FRAMES=$(ffprobe -v error -select_streams v:0 -count_frames \
-show_entries stream=nb_read_frames "$VIDEO" | grep nb_read_frames | cut -d= -f2)
local END=$(date +%s.%N)
local DURATION=$(echo "$END - $START" | bc)
local FPS=$(echo "scale=2; $FRAMES / $DURATION" | bc)
echo "處理幀率: $FPS fps"
}
1.2.4 RAG 效能測試
#!/bin/bash
# benchmark/rag_benchmark.sh
# RAG 回應時間
rag_benchmark() {
echo "=== RAG 效能測試 ==="
# 搜尋延遲測試
for QUERY in "test1" "test2" "test3"; do
START=$(date +%s.%N)
curl -X POST http://localhost:3002/api/v1/search \
-H "Content-Type: application/json" \
-d "{\"query\":\"$QUERY\",\"limit\":10}" \
-s > /dev/null
END=$(date +%s.%N)
DURATION=$(echo "scale=3; $END - $START" | bc)
echo "搜尋延遲: ${DURATION}s"
done
# 並發測試
ab -n 100 -c 10 -p benchmark/query.json \
-T application/json \
http://localhost:3002/api/v1/search
# QPS 測試
wrk -t4 -c100 -d30s \
-s benchmark/post.lua \
http://localhost:3002/api/v1/search
}
# 向量搜尋效能
vector_search_benchmark() {
echo "=== 向量搜尋效能 ==="
# 插入測試
python3 scripts/benchmark/vector_insert_benchmark.py \
--count 10000
# 搜尋測試
python3 scripts/benchmark/vector_search_benchmark.py \
--queries 1000 \
--top-k 100
}
1.3 跑分報告格式
{
"benchmark": {
"timestamp": "2026-03-23T12:00:00Z",
"system": {
"model": "Mac mini (M4)",
"cpu": "Apple M4",
"memory": "16 GB",
"disk": "Thunderbolt NVMe 2TB"
},
"results": {
"disk": {
"sequential_read": "2800 MB/s",
"sequential_write": "2600 MB/s",
"random_read": "150 MB/s",
"random_write": "180 MB/s"
},
"database": {
"postgresql_qps": 15000,
"mongodb_insert": 50000,
"redis_qps": 100000,
"qdrant_search_latency": "5ms"
},
"video_processing": {
"asr_fps": 45,
"yolo_fps": 30,
"ocr_fps": 25,
"full_pipeline_time": "120s"
},
"rag": {
"search_latency": "50ms",
"qps": 200,
"vector_insert_rate": "1000/s"
}
}
}
}
二、完整自動測試
2.1 測試架構
測試層級:
├── 1. 單元測試 (Unit Tests)
│ ├── Rust 單元測試
│ └── Python 單元測試
│
├── 2. 整合測試 (Integration Tests)
│ ├── API 端點測試
│ ├── 資料庫整合測試
│ └── 服務通訊測試
│
├── 3. 端對端測試 (E2E Tests)
│ ├── 影片處理流程
│ ├── RAG 搜尋流程
│ └── 工作流程自動化
│
└── 4. 系統測試 (System Tests)
├── 完整安裝測試
├── 升級測試
├── 備份還原測試
└── 效能測試
2.2 單元測試
#!/bin/bash
# tests/unit_tests.sh
run_rust_unit_tests() {
echo "=== Rust 單元測試 ==="
cd /Volumes/Momentry/Apps/Developer/momentry_core
# 執行所有單元測試
cargo test --lib
# 測試覆蓋率
cargo tarpaulin --out Xml --output-dir target/coverage
# 特定模組測試
cargo test --lib core::db
cargo test --lib core::config
cargo test --lib core::embedding
}
run_python_unit_tests() {
echo "=== Python 單元測試 ==="
cd /Volumes/Momentry/Scripts
# 執行所有 Python 測試
python3 -m pytest tests/ -v --cov=scripts --cov-report=xml
# 特定模組
python3 -m pytest tests/test_asr_processor.py -v
python3 -m pytest tests/test_yolo_processor.py -v
}
2.3 整合測試
#!/bin/bash
# tests/integration_tests.sh
# API 端點測試
api_integration_tests() {
echo "=== API 端點測試 ==="
# 健康檢查
curl -s http://localhost:3002/api/v1/health | jq '.status' | grep -q "ok"
# 測試端點
for ENDPOINT in \
"/api/v1/videos" \
"/api/v1/search" \
"/api/v1/n8n/search"
do
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3002$ENDPOINT)
[ "$RESPONSE" -eq 200 ] || echo "FAIL: $ENDPOINT"
done
# 認證測試
python3 tests/integration/test_api_auth.py
}
# 資料庫整合測試
database_integration_tests() {
echo "=== 資料庫整合測試 ==="
# PostgreSQL
python3 tests/integration/test_postgresql.py
# MongoDB
python3 tests/integration/test_mongodb.py
# Redis
python3 tests/integration/test_redis.py
# Qdrant
python3 tests/integration/test_qdrant.py
}
# 服務通訊測試
service_communication_tests() {
echo "=== 服務通訊測試 ==="
# n8n 通訊
python3 tests/integration/test_n8n_communication.py
# SFTPGo 通訊
python3 tests/integration/test_sftpgo_communication.py
# Caddy 反向代理
python3 tests/integration/test_caddy_proxy.py
}
2.4 端對端測試
#!/bin/bash
# tests/e2e_tests.sh
# 影片處理流程測試
video_processing_e2e() {
echo "=== 影片處理 E2E 測試 ==="
# 1. 上傳影片
VIDEO_ID=$(curl -X POST http://localhost:3002/api/v1/videos \
-F "video=@/Volumes/Momentry/Data/Test/videos/sample.mp4" \
| jq -r '.uuid')
# 2. 等待處理完成
for i in {1..60}; do
STATUS=$(curl -s http://localhost:3002/api/v1/videos/$VIDEO_ID \
| jq -r '.status')
[ "$STATUS" = "completed" ] && break
sleep 5
done
# 3. 驗證結果
[ "$STATUS" = "completed" ] || exit 1
# 4. 清理
curl -X DELETE http://localhost:3002/api/v1/videos/$VIDEO_ID
}
# RAG 搜尋流程測試
rag_search_e2e() {
echo "=== RAG 搜尋 E2E 測試 ==="
# 1. 搜尋測試
RESULT=$(curl -X POST http://localhost:3002/api/v1/search \
-H "Content-Type: application/json" \
-d '{"query":"test","limit":5}')
# 2. 驗證結果
COUNT=$(echo $RESULT | jq '.count')
[ "$COUNT" -gt 0 ] || exit 1
# 3. 效能測試
for QUERY in "video" "audio" "text"; do
curl -X POST http://localhost:3002/api/v1/search \
-H "Content-Type: application/json" \
-d "{\"query\":\"$QUERY\",\"limit\":10}" \
-s > /dev/null
done
}
# 工作流程自動化測試
workflow_automation_e2e() {
echo "=== 工作流程 E2E 測試 ==="
# n8n 工作流程測試
python3 tests/e2e/test_n8n_workflows.py
}
2.5 系統測試
#!/bin/bash
# tests/system_tests.sh
# 完整安裝測試
full_installation_test() {
echo "=== 完整安裝測試 ==="
# 1. 檢查所有服務
SERVICES=(
"postgresql"
"mongodb"
"mariadb"
"redis"
"qdrant"
"ollama"
"caddy"
"gitea"
"php"
"n8n"
"sftpgo"
"momentry"
)
for SERVICE in "${SERVICES[@]}"; do
if launchctl list | grep -q "$SERVICE"; then
echo "✅ $SERVICE: Running"
else
echo "❌ $SERVICE: Not running"
FAILED_TESTS+=("$SERVICE")
fi
done
# 2. 執行整合測試
./tests/integration_tests.sh
# 3. 執行 E2E 測試
./tests/e2e_tests.sh
}
# 升級測試
upgrade_test() {
echo "=== 升級測試 ==="
# 1. 備份當前版本
./scripts/backup.sh
# 2. 模擬升級
./scripts/upgrade/test_upgrade.sh
# 3. 驗證功能
./tests/integration_tests.sh
# 4. 回滾測試
./scripts/backup/restore.sh
}
# 備份還原測試
backup_restore_test() {
echo "=== 備份還原測試 ==="
# 1. 建立備份
./scripts/backup/backup_create.sh
# 2. 模擬資料損壞
./scripts/test/corrupt_data.sh
# 3. 還原備份
./scripts/backup/backup_restore.sh
# 4. 驗證資料完整性
./scripts/test/verify_data_integrity.sh
}
2.6 測試報告
#!/bin/bash
# tests/generate_report.sh
generate_test_report() {
REPORT="/Volumes/Momentry/Logs/test_report_$(date +%Y%m%d_%H%M%S).json"
jq -n \
--arg timestamp "$(date -Iseconds)" \
--argjson unit "$(cat logs/unit_test_results.json)" \
--argjson integration "$(cat logs/integration_test_results.json)" \
--argjson e2e "$(cat logs/e2e_test_results.json)" \
--argjson system "$(cat logs/system_test_results.json)" \
'{
timestamp: $timestamp,
unit_tests: $unit,
integration_tests: $integration,
e2e_tests: $e2e,
system_tests: $system,
summary: {
total: ($unit.total + $integration.total + $e2e.total + $system.total),
passed: ($unit.passed + $integration.passed + $e2e.passed + $system.passed),
failed: ($unit.failed + $integration.failed + $e2e.failed + $system.failed)
}
}' > "$REPORT"
echo "測試報告: $REPORT"
}
三、燒機程序
3.1 目的
驗證系統在以下壓力條件下的穩定性:
- 長時間運行 (24-72 小時)
- 高負載運行
- 極端條件測試
- 資源耗盡恢復
3.2 燒機項目
3.2.1 CPU 燒機
#!/bin/bash
# stress/cpu_stress.sh
cpu_burn() {
echo "=== CPU 燒機 (4小時) ==="
# 使用 stress-ng
stress-ng --cpu $(sysctl -n hw.ncpu) \
--timeout 14400 \
--metrics-brief
# 或使用 sysbench
sysbench cpu --cpu-max-prime=5000000 \
--threads=$(sysctl -n hw.ncpu) \
--time=14400 run
}
3.2.2 記憶體燒機
#!/bin/bash
# stress/memory_stress.sh
memory_burn() {
echo "=== 記憶體燒機 (4小時) ==="
# 記憶體壓力測試
stress-ng --vm 4 --vm-bytes 80% \
--timeout 14400 \
--metrics-brief
# 記憶體洩漏檢測
./tests/memory_leak_test.sh
}
3.2.3 磁碟 I/O 燒機
#!/bin/bash
# stress/disk_stress.sh
disk_burn() {
echo "=== 磁碟 I/O 燒機 (8小時) ==="
# 順序 I/O
fio --name=seqwrite --rw=write --bs=1M \
--size=10G --numjobs=4 \
--directory=/Volumes/Momentry/test \
--time_based --runtime=28800
# 隨機 I/O
fio --name=randrw --rw=randrw --bs=4k \
--size=10G --numjobs=8 \
--directory=/Volumes/Momentry/test \
--time_based --runtime=28800
# 混合負載
fio --name=mixed --rw=randrw --bsrange=4k-1M \
--size=10G --numjobs=4 \
--directory=/Volumes/Momentry/test \
--time_based --runtime=28800
}
3.2.4 資料庫燒機
#!/bin/bash
# stress/database_stress.sh
database_burn() {
echo "=== 資料庫燒機 (8小時) ==="
# PostgreSQL 壓力測試
pgbench -c 50 -j 8 -T 28800 momentry
# 並發連線測試
for i in {1..100}; do
psql -h localhost -U momentry -d momentry -c "SELECT * FROM videos LIMIT 1;" &
done
wait
# MongoDB 壓力測試
mongosh --eval '
use stress_test;
for (let i = 0; i < 100000; i++) {
db.test.insertOne({index: i, timestamp: new Date()});
if (i % 1000 === 0) print("Inserted", i);
}
'
# Redis 壓力測試
redis-benchmark -t set,get,lpush,rpop -n 10000000 -c 100
}
3.2.5 網路燒機
#!/bin/bash
# stress/network_stress.sh
network_burn() {
echo "=== 網路燒機 (4小時) ==="
# TCP 連線壓力
iperf3 -s -D
iperf3 -c localhost -t 14400 -P 10
# HTTP 壓力
wrk -t4 -c100 -d14400s \
http://localhost:3002/api/v1/videos
# API 並發測試
hey -z 14400s -c 100 \
-m POST \
-H "Content-Type: application/json" \
-d '{"query":"test","limit":10}' \
http://localhost:3002/api/v1/search
}
3.2.6 應用程式燒機
#!/bin/bash
# stress/application_stress.sh
application_burn() {
echo "=== 應用程式燒機 (24小時) ==="
# 1. 影片處理壓力測試
for i in {1..100}; do
cargo run --bin momentry -- \
process /Volumes/Momentry/Data/Test/videos/sample_$i.mp4 \
--modules all &
done
wait
# 2. RAG 搜尋壓力測試
while true; do
curl -X POST http://localhost:3002/api/v1/search \
-H "Content-Type: application/json" \
-d "{\"query\":\"test query $(date +%s)\",\"limit\":10}"
sleep 1
done &
# 3. n8n 工作流程壓力
while true; do
curl -X POST http://localhost:5678/webhook/test \
-H "Content-Type: application/json" \
-d '{"test":"data"}'
sleep 5
done &
# 4. 監控程序
./stress/monitor_resources.sh
}
3.3 燒機監控
#!/bin/bash
# stress/monitor_resources.sh
monitor_burn() {
LOG="/Volumes/Momentry/Logs/burn_$(date +%Y%m%d).log"
while true; do
TIMESTAMP=$(date -Iseconds)
# CPU 使用率
CPU=$(top -l 1 | grep "CPU usage" | awk '{print $3}')
# 記憶體使用率
MEM=$(top -l 1 | grep "PhysMem" | awk '{print $2}')
# 磁碟 I/O
DISK=$(iostat -d -c 1 | tail -n +2)
# 溫度 (如果可用)
TEMP=$(sysctl -n hw.temperature 2>/dev/null || echo "N/A")
# 服務狀態
SERVICES=$(system_services_status)
# 記錄
echo "[$TIMESTAMP] CPU: $CPU | MEM: $MEM | TEMP: $TEMP" >> "$LOG"
echo "$SERVICES" >> "$LOG"
sleep 60
done
}
system_services_status() {
for SVC in postgresql mongodb redis qdrant ollama caddy n8n momentry; do
if launchctl list | grep -q "$SVC"; then
echo "✅ $SVC: Running"
else
echo "❌ $SVC: Stopped"
fi
done
}
3.4 燒機報告
#!/bin/bash
# stress/stress_report.sh
generate_stress_report() {
REPORT="/Volumes/Momentry/Logs/stress_report_$(date +%Y%m%d).json"
jq -n \
--arg start_time "$(head -1 /Volumes/Momentry/Logs/burn_*.log)" \
--arg end_time "$(tail -1 /Volumes/Momentry/Logs/burn_*.log)" \
--argjson cpu "$(cat logs/cpu_stats.json)" \
--argjson memory "$(cat logs/memory_stats.json)" \
--argjson disk "$(cat logs/disk_stats.json)" \
--argjson network "$(cat logs/network_stats.json)" \
'{
start_time: $start_time,
end_time: $end_time,
duration: "24 hours",
results: {
cpu: {
max_usage: $cpu.max,
avg_usage: $cpu.avg,
peak_temp: $cpu.temp
},
memory: {
max_usage: $memory.max,
leaks: $memory.leaks
},
disk: {
total_io: $disk.total,
errors: $disk.errors
},
network: {
total_throughput: $network.total,
connections: $network.connections
}
},
status: ($cpu.max < 90 and $memory.max < 90) ? "PASS" : "FAIL"
}' > "$REPORT"
echo "燒機報告: $REPORT"
}
3.5 燒機階段
階段 1: 基礎燒機 (4小時)
├── CPU 壓力測試
├── 記憶體壓力測試
└── 磁碟 I/O 壓力測試
階段 2: 資料庫燒機 (8小時)
├── PostgreSQL 並發測試
├── MongoDB 讀寫測試
├── Redis 壓力測試
└── Qdrant 向量搜尋測試
階段 3: 網路燒機 (4小時)
├── TCP 連線壓力
├── HTTP 並發測試
└── API 壓力測試
階段 4: 應用程式燒機 (24小時)
├── 影片處理壓力
├── RAG 搜尋壓力
├── n8n 工作流程壓力
└── 完整流程壓力
階段 5: 混合燒機 (24小時)
├── 隨機負載組合
├── 峰值負載測試
└── 極端條件測試
總計: 64 小時
四、測試數據
4.1 種子數據清單
/Volumes/Momentry/Backup/Base/seed-data/
├── videos/
│ ├── sample_1080p.mp4 # 1080p 測試影片 (100MB)
│ ├── sample_720p.mp4 # 720p 測試影片 (50MB)
│ ├── sample_480p.mp4 # 480p 測試影片 (20MB)
│ └── sample_short.mp4 # 短影片 (5MB)
│
├── images/
│ ├── test_image_1.jpg # 測試圖片
│ ├── test_image_2.png # 測試圖片
│ └── test_thumbnail.jpg # 縮圖測試
│
├── audio/
│ ├── test_audio.mp3 # 音訊測試
│ └── test_speech.wav # 語音測試
│
├── database/
│ ├── postgres_seed.sql # PostgreSQL 種子資料
│ ├── mongodb_seed.js # MongoDB 種子資料
│ └── redis_seed.rdb # Redis 種子資料
│
└── configs/
├── n8n_workflows/ # n8n 工作流程
├── caddy_config/ # Caddy 配置
└── env_templates/ # 環境變數範本
4.2 種子資料腳本
#!/bin/bash
# scripts/seed_data/load_seed_data.sh
load_seed_data() {
echo "=== 載入種子資料 ==="
# 1. PostgreSQL
psql -U momentry -d momentry < /Volumes/Momentry/Backup/Base/seed-data/database/postgres_seed.sql
# 2. MongoDB
mongosh momentry < /Volumes/Momentry/Backup/Base/seed-data/database/mongodb_seed.js
# 3. Redis
redis-cli --rdb /Volumes/Momentry/Backup/Base/seed-data/database/redis_seed.rdb
# 4. n8n 工作流程
for WORKFLOW in /Volumes/Momentry/Backup/Base/seed-data/configs/n8n_workflows/*.json; do
curl -X POST http://localhost:5678/api/v1/workflows \
-H "X-N8N-API-KEY: $N8N_API_KEY" \
-H "Content-Type: application/json" \
-d "@$WORKFLOW"
done
# 5. 測試影片
cp -r /Volumes/Momentry/Backup/Base/seed-data/videos/* \
/Volumes/Momentry/Data/Test/videos/
# 6. 註冊測試影片
for VIDEO in /Volumes/Momentry/Data/Test/videos/*.mp4; do
cargo run --bin momentry -- register "$VIDEO"
done
}
4.3 測試配置
# Config/test_config.yaml
test:
seed_data:
videos:
- path: /Volumes/Momentry/Data/Test/videos/sample_1080p.mp4
size: 100MB
duration: 120s
- path: /Volumes/Momentry/Data/Test/videos/sample_720p.mp4
size: 50MB
duration: 60s
queries:
- "test"
- "video"
- "search"
- "處理"
- "測試"
workflows:
- name: "Test Webhook"
path: configs/n8n_workflows/test_webhook.json
- name: "Test Search"
path: configs/n8n_workflows/test_search.json
users:
- username: test_admin
role: admin
api_key: test_admin_key_12345
- username: test_user
role: user
api_key: test_user_key_67890
expected_results:
video_processing:
max_time: 300s
search:
max_latency: 100ms
workflow:
max_time: 60s
五、測試腳本整合
5.1 主控腳本
#!/bin/bash
# tests/run_all_tests.sh
set -e
SCRIPT_DIR="/Volumes/Momentry/Scripts/tests"
LOG_DIR="/Volumes/Momentry/Logs/tests"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
# 初始化
init() {
echo "=== 初始化測試環境 ==="
mkdir -p "$LOG_DIR"
# 載入種子資料
./scripts/seed_data/load_seed_data.sh
# 檢查服務狀態
./scripts/health_check.sh
}
# 單元測試
unit_tests() {
echo "=== 執行單元測試 ===" | tee -a "$LOG_DIR/unit_$TIMESTAMP.log"
./tests/unit_tests.sh 2>&1 | tee -a "$LOG_DIR/unit_$TIMESTAMP.log"
}
# 整合測試
integration_tests() {
echo "=== 執行整合測試 ===" | tee -a "$LOG_DIR/integration_$TIMESTAMP.log"
./tests/integration_tests.sh 2>&1 | tee -a "$LOG_DIR/integration_$TIMESTAMP.log"
}
# 端對端測試
e2e_tests() {
echo "=== 執行端對端測試 ===" | tee -a "$LOG_DIR/e2e_$TIMESTAMP.log"
./tests/e2e_tests.sh 2>&1 | tee -a "$LOG_DIR/e2e_$TIMESTAMP.log"
}
# 燒機測試
burn_in_tests() {
echo "=== 執行燒機測試 ===" | tee -a "$LOG_DIR/burn_$TIMESTAMP.log"
./stress/cpu_stress.sh 2>&1 | tee -a "$LOG_DIR/burn_$TIMESTAMP.log"
./stress/memory_stress.sh 2>&1 | tee -a "$LOG_DIR/burn_$TIMESTAMP.log"
./stress/disk_stress.sh 2>&1 | tee -a "$LOG_DIR/burn_$TIMESTAMP.log"
./stress/database_stress.sh 2>&1 | tee -a "$LOG_DIR/burn_$TIMESTAMP.log"
./stress/application_stress.sh 2>&1 | tee -a "$LOG_DIR/burn_$TIMESTAMP.log"
}
# 跑分測試
benchmark_tests() {
echo "=== 執行跑分測試 ===" | tee -a "$LOG_DIR/benchmark_$TIMESTAMP.log"
./benchmark/hardware_benchmark.sh 2>&1 | tee -a "$LOG_DIR/benchmark_$TIMESTAMP.log"
./benchmark/database_benchmark.sh 2>&1 | tee -a "$LOG_DIR/benchmark_$TIMESTAMP.log"
./benchmark/video_benchmark.sh 2>&1 | tee -a "$LOG_DIR/benchmark_$TIMESTAMP.log"
./benchmark/rag_benchmark.sh 2>&1 | tee -a "$LOG_DIR/benchmark_$TIMESTAMP.log"
}
# 生成報告
generate_reports() {
echo "=== 生成測試報告 ==="
# 整合測試報告
./tests/generate_report.sh
# 燒機報告
./stress/stress_report.sh
# 跑分報告
./benchmark/benchmark_report.sh
}
# 主程序
main() {
echo "========================================="
echo "Momentry 系統測試開始: $TIMESTAMP"
echo "========================================="
init
unit_tests
integration_tests
e2e_tests
benchmark_tests
burn_in_tests
generate_reports
echo "========================================="
echo "測試完成: $(date)"
echo "========================================="
}
# 執行
main "$@"
六、測試排程
# 使用 crontab 設定自動測試
# 每日快速測試 (30分鐘)
0 2 * * * /Volumes/Momentry/Scripts/tests/daily_quick_test.sh
# 每週完整測試 (4小時)
0 3 * * 0 /Volumes/Momentry/Scripts/tests/weekly_full_test.sh
# 每月燒機測試 (72小時)
0 4 1 * * /Volumes/Momentry/Scripts/tests/monthly_burn_test.sh
七、預期結果
7.1 跑分基準
| 項目 | M3 基準 | M4 基準 | 單位 |
|---|---|---|---|
| CPU 效能 | 8000 | 10000 | Geekbench 單核 |
| 記憶體頻寬 | 100 | 120 | GB/s |
| 磁碟讀取 | 2500 | 2800 | MB/s |
| 磁碟寫入 | 2000 | 2600 | MB/s |
| PostgreSQL QPS | 10000 | 15000 | queries/s |
| Redis QPS | 80000 | 100000 | ops/s |
| 影片處理 | 30 | 45 | fps |
| RAG 延遲 | 100 | 50 | ms |
7.2 測試通過標準
| 測試類型 | 通過標準 |
|---|---|
| 單元測試 | 100% 通過 |
| 整合測試 | 100% 通過 |
| 端對端測試 | 100% 通過 |
| 燒機測試 | 無當機、無記憶體洩漏 |
| 效能測試 | 低於基準 10% 內 |
八、待確認事項
-
燒機時間
- 基礎燒機: 4小時?
- 完整燒機: 24小時?72小時?
-
測試影片
- 是否提供測試影片?
- 需要哪些解析度?
-
效能基準
- M3/M4 的預期基準?
- 是否需要比較參考數據?
-
監控頻率
- 燒機期間監控頻率?(1分鐘?5分鐘?)
-
失敗處理
- 測試失敗時是否繼續?
- 是否需要自動通知?
計劃狀態: 📋 等待確認後執行
您想調整哪些部分?