import { chessUserJourney } from '../scenarios/chessUserScenario.js'; import { thresholds } from '../config.js'; import { Counter } from 'k6/metrics'; const START_USERS = parseInt(__ENV.START_USERS || '1', 10); const MAX_USERS = parseInt(__ENV.MAX_USERS || '100', 10); const RAMP_DURATION = parseInt(__ENV.RAMP_DURATION || '300', 10); const userLimitCounter = new Counter('user_limit_tracker'); export const options = { stages: [ { duration: `${RAMP_DURATION}s`, target: MAX_USERS, }, ], thresholds, }; export default function () { chessUserJourney(); userLimitCounter.add(1); } export function handleSummary(data) { const metrics = data.metrics; // Find breaking point by analyzing metrics over time let breakingPointUsers = START_USERS; let maxSuccessfulUsers = START_USERS; // Check final threshold results const summaryText = JSON.stringify(data.metrics, null, 2); // Calculate estimated limit based on error rates if (metrics['http_req_failed']) { const failedReqs = metrics['http_req_failed'].values.count || 0; const totalReqs = metrics['http_reqs']?.values.count || 1; const failureRate = (failedReqs / totalReqs) * 100; // Estimate breaking point based on load curve const timeElapsed = RAMP_DURATION; const usersPerSecond = MAX_USERS / timeElapsed; const estimatedBreakingPoint = Math.floor((failureRate / 100) * MAX_USERS); if (estimatedBreakingPoint > 0) { maxSuccessfulUsers = Math.max(estimatedBreakingPoint - 1, START_USERS); } } // Print summary console.log(''); console.log('=== STRESS TEST LIMIT ANALYSIS ==='); console.log(`Test Duration: ${RAMP_DURATION}s`); console.log(`Ramp Range: ${START_USERS} → ${MAX_USERS} users`); console.log(`Estimated System Limit: ${maxSuccessfulUsers} concurrent users`); console.log(''); return { stdout: summaryText, }; }