feat: Added k6 performance tests
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import http from 'k6/http';
|
||||
import { check } from 'k6';
|
||||
import { BASE_URL, httpConfig } from '../config.js';
|
||||
|
||||
export function chessUserJourney() {
|
||||
const username = `user_${Date.now()}_${__VU}_${Math.random().toString(36).substring(2, 10)}`;
|
||||
const email = `${username}@test.com`;
|
||||
const password = 'Password123!';
|
||||
|
||||
// Register
|
||||
const registerRes = http.post(`${BASE_URL}/api/account`, JSON.stringify({
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
}), httpConfig);
|
||||
check(registerRes, { 'Register: status 200': (r) => r.status === 200 });
|
||||
|
||||
// Login
|
||||
const loginRes = http.post(`${BASE_URL}/api/account/login`, JSON.stringify({
|
||||
username,
|
||||
password,
|
||||
}), httpConfig);
|
||||
check(loginRes, { 'Login: status 200': (r) => r.status === 200 });
|
||||
|
||||
const jwt = loginRes.json('token');
|
||||
if (!jwt) {
|
||||
console.error('Failed to get JWT token');
|
||||
return;
|
||||
}
|
||||
|
||||
const authHeaders = {
|
||||
...httpConfig.headers,
|
||||
'Authorization': `Bearer ${jwt}`,
|
||||
};
|
||||
|
||||
// Import Game
|
||||
const importRes = http.post(`${BASE_URL}/api/board/game/import/fen`, JSON.stringify({
|
||||
fen: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',
|
||||
white: { id: username, displayName: username },
|
||||
black: { id: `opponent_${__VU}`, displayName: 'Opponent' },
|
||||
timeControl: { limitSeconds: 300, incrementSeconds: 3 },
|
||||
}), { headers: authHeaders, timeout: '30s' });
|
||||
check(importRes, { 'Import Game: status 200/201': (r) => r.status === 200 || r.status === 201 });
|
||||
|
||||
const gameId = importRes.json('gameId');
|
||||
if (!gameId) {
|
||||
console.error('Failed to get gameId');
|
||||
return;
|
||||
}
|
||||
|
||||
// Make moves
|
||||
const moves = ['e2e4', 'e7e5', 'g1f3'];
|
||||
for (const uci of moves) {
|
||||
const moveRes = http.post(`${BASE_URL}/api/board/game/${gameId}/move/${uci}`, null, {
|
||||
headers: authHeaders,
|
||||
timeout: '30s',
|
||||
});
|
||||
check(moveRes, { [`Move ${uci}: status 200/201`]: (r) => r.status === 200 || r.status === 201 });
|
||||
}
|
||||
|
||||
// Resign
|
||||
const resignRes = http.post(`${BASE_URL}/api/board/game/${gameId}/resign`, null, {
|
||||
headers: authHeaders,
|
||||
timeout: '30s',
|
||||
});
|
||||
check(resignRes, { 'Resign: status 200/201/204': (r) => [200, 201, 204].includes(r.status) });
|
||||
}
|
||||
Reference in New Issue
Block a user