backend/test/tests/smoke/smoke-health-test.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2025-11-07 07:44:23 +00:00
/**
* 健康檢查冒煙測試
*
* 此測試用於 Dev/QA 環境快速驗證系統健康狀態
* 測試重點系統可用性響應時間
*/
import { healthCheck } from '../../scenarios/apis/health.js';
export const options = {
scenarios: {
smoke_health: {
executor: 'shared-iterations',
vus: 1,
iterations: 5, // 執行 5 次健康檢查
maxDuration: '10s',
tags: { test_type: 'smoke', api: 'health' },
},
},
thresholds: {
checks: ['rate==1.0'], // 所有檢查必須通過
http_req_duration: ['p(95)<500'], // 95% 的請求應在 500ms 內完成
health_check_success: ['rate==1.0'], // 健康檢查成功率應為 100%
},
};
export default function () {
const baseUrl = __ENV.BASE_URL || 'http://localhost:8888';
const result = healthCheck({ baseUrl });
if (!result.success) {
console.error('Smoke test failed: Health check failed');
return;
}
console.log(`Health check passed: Status ${result.status}, Response time ${result.responseTime}ms`);
}