/** * 使用者資料流程負載測試 * * 此測試用於 Pre-release 環境,模擬正常負載下的使用者資料管理流程。 * 測試重點:系統在正常負載下的流程性能和穩定性。 */ import { userProfileInitializationFlow } from '../../scenarios/e2e/user-profile-flow.js'; export const options = { scenarios: { load_user_profile_flow: { executor: 'ramping-vus', startVUs: 0, stages: [ { duration: '30s', target: 5 }, // 30 秒內增加到 5 個 VU { duration: '1m', target: 5 }, // 維持 5 個 VU 1 分鐘 { duration: '30s', target: 10 }, // 30 秒內增加到 10 個 VU { duration: '1m', target: 10 }, // 維持 10 個 VU 1 分鐘 { duration: '30s', target: 0 }, // 30 秒內減少到 0 個 VU ], gracefulRampDown: '30s', tags: { test_type: 'load', api: 'user', flow: 'profile', environment: 'pre' }, }, }, thresholds: { checks: ['rate>0.95'], // 95% 的檢查必須通過 http_req_duration: ['p(95)<3000'], // 95% 的請求應在 3 秒內完成 http_req_failed: ['rate<0.05'], // 失敗率應低於 5% }, }; export default function () { const baseUrl = __ENV.BASE_URL || 'https://localhost:8888'; const timestamp = Date.now(); const randomId = Math.floor(Math.random() * 1000000); const loginId = `load_flow_${timestamp}_${randomId}@example.com`; const password = 'LoadTest123!'; // 運行完整的使用者資料初始化流程 const result = userProfileInitializationFlow({ baseUrl, loginId, password, updateData: { nickname: `LoadFlow_${timestamp}_${randomId}`, preferred_language: 'zh-tw', currency: 'TWD', }, }); if (!result.success) { console.error(`Load test failed: ${result.step} - ${result.error}`); return; } console.log('Load test: User profile flow completed successfully'); }