c50ccd258f
refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests style: 为Java类添加文档注释 docs: 更新.gitignore和配置文件 test: 添加性能测试和Playwright测试脚本 chore: 清理旧测试文件和配置
67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
import http from 'k6/http';
|
|
import { check, sleep } from 'k6';
|
|
|
|
const BASE_URL = __ENV.BASE_URL || 'http://localhost:8080';
|
|
const TEST_DURATION = __ENV.DURATION || '30s';
|
|
const VUS = __ENV.VUS || '10';
|
|
|
|
export let options = {
|
|
scenarios: {
|
|
constant_load: {
|
|
executor: 'constant-vus',
|
|
vus: parseInt(VUS),
|
|
duration: TEST_DURATION,
|
|
startTime: '0s',
|
|
},
|
|
},
|
|
thresholds: {
|
|
http_req_duration: ['p(95)<500'],
|
|
http_req_failed: ['rate<0.05'],
|
|
},
|
|
};
|
|
|
|
export function setup() {
|
|
let loginRes = http.post(`${BASE_URL}/api/auth/login`, JSON.stringify({
|
|
username: 'admin',
|
|
password: 'admin123'
|
|
}), {
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
|
|
check(loginRes, {
|
|
'login successful': (r) => r.status === 200,
|
|
'has token': (r) => r.json('token') !== undefined,
|
|
});
|
|
|
|
return {
|
|
token: loginRes.json('token'),
|
|
};
|
|
}
|
|
|
|
export default function (data) {
|
|
let headers = {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${data.token}`,
|
|
};
|
|
|
|
let responses = http.batch([
|
|
['GET', `${BASE_URL}/api/users`, null, { headers }],
|
|
['GET', `${BASE_URL}/api/roles`, null, { headers }],
|
|
['GET', `${BASE_URL}/api/config`, null, { headers }],
|
|
['GET', `${BASE_URL}/api/notices`, null, { headers }],
|
|
['GET', `${BASE_URL}/api/files`, null, { headers }],
|
|
]);
|
|
|
|
responses.forEach((res) => {
|
|
check(res, {
|
|
'status is 200': (r) => r.status === 200,
|
|
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
});
|
|
});
|
|
|
|
sleep(1);
|
|
}
|
|
|
|
export function teardown(data) {
|
|
console.log('Performance test completed');
|
|
} |