backend/test/tests/prod/nightly-health-test.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-11-07 07:44:23 +00:00
/**
* 健康檢查夜間監控
*
* 此測試用於 Production 環境持續監控系統健康狀態
* 測試重點系統可用性監控識別性能退化
*/
import { healthCheck } from '../../scenarios/apis/health.js';
export const options = {
scenarios: {
nightly_health: {
executor: 'constant-arrival-rate',
rate: 1, // 每秒 1 個請求
timeUnit: '1s',
duration: '10m', // 執行 10 分鐘
preAllocatedVUs: 2,
maxVUs: 5,
tags: { test_type: 'nightly', api: 'health', environment: 'prod' },
},
},
thresholds: {
checks: ['rate==1.0'], // 所有檢查必須通過
http_req_duration: ['p(95)<500'], // 95% 的請求應在 500ms 內完成
health_check_success: ['rate==1.0'], // 健康檢查成功率應為 100%
http_req_failed: ['rate==0'], // 不允許失敗
},
};
export default function () {
const baseUrl = __ENV.BASE_URL || 'http://localhost:8888';
const result = healthCheck({ baseUrl });
if (!result.success) {
console.error(`Health check failed: Status ${result.status}, Response time ${result.responseTime}ms`);
return;
}
// 記錄健康檢查結果(在實際環境中,這可以發送到監控系統)
console.log(`Health check passed: Status ${result.status}, Response time ${result.responseTime}ms`);
}