feat: 添加异常日志功能并优化UI样式
refactor: 重构后端查询逻辑和API响应处理 fix: 修复用户角色更新和文件上传问题 test: 添加前端性能测试脚本和E2E测试用例 chore: 更新依赖版本和配置文件 docs: 添加环境检查脚本和测试文档 style: 统一表格标签样式和路由命名 perf: 优化前端页面加载速度和响应时间
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import http from 'k6/http';
|
||||
import { check, sleep } from 'k6';
|
||||
import { Rate } from 'k6/metrics';
|
||||
|
||||
export let options = {
|
||||
stages: [
|
||||
{ duration: '30s', target: 10 },
|
||||
{ duration: '1m', target: 20 },
|
||||
{ duration: '30s', target: 0 },
|
||||
],
|
||||
thresholds: {
|
||||
http_req_duration: ['p(95)<500'],
|
||||
http_req_failed: ['rate<0.01'],
|
||||
},
|
||||
};
|
||||
|
||||
const BASE_URL = __ENV.BASE_URL || 'http://localhost:8084';
|
||||
|
||||
export function setup() {
|
||||
console.log('Starting API performance test...');
|
||||
console.log(`Base URL: ${BASE_URL}`);
|
||||
}
|
||||
|
||||
export default function () {
|
||||
const endpoints = [
|
||||
{ method: 'GET', url: `${BASE_URL}/api/health` },
|
||||
{ method: 'GET', url: `${BASE_URL}/api/users` },
|
||||
{ method: 'GET', url: `${BASE_URL}/api/roles` },
|
||||
{ method: 'GET', url: `${BASE_URL}/api/config` },
|
||||
];
|
||||
|
||||
const endpoint = endpoints[Math.floor(Math.random() * endpoints.length)];
|
||||
|
||||
let response;
|
||||
if (endpoint.method === 'GET') {
|
||||
response = http.get(endpoint.url, {
|
||||
tags: { name: endpoint.url },
|
||||
});
|
||||
}
|
||||
|
||||
check(response, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 500ms': (r) => r.timings.duration < 500,
|
||||
'response body is not empty': (r) => r.body.length > 0,
|
||||
});
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
export function teardown(data) {
|
||||
console.log('API performance test completed');
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import http from 'k6/http';
|
||||
import { check, sleep } from 'k6';
|
||||
|
||||
export let options = {
|
||||
stages: [
|
||||
{ duration: '1m', target: 20 },
|
||||
{ duration: '2m', target: 50 },
|
||||
{ duration: '2m', target: 100 },
|
||||
{ duration: '2m', target: 50 },
|
||||
{ duration: '1m', target: 0 },
|
||||
],
|
||||
thresholds: {
|
||||
http_req_duration: ['p(95)<1000'],
|
||||
http_req_failed: ['rate<0.01'],
|
||||
},
|
||||
};
|
||||
|
||||
const BASE_URL = __ENV.BASE_URL || 'http://localhost:8084';
|
||||
|
||||
export function setup() {
|
||||
console.log('Starting concurrent load test...');
|
||||
console.log(`Base URL: ${BASE_URL}`);
|
||||
console.log('Max concurrent users: 100');
|
||||
}
|
||||
|
||||
export default function () {
|
||||
const scenarios = [
|
||||
{
|
||||
name: 'read-operations',
|
||||
weight: 0.7,
|
||||
operations: [
|
||||
{ method: 'GET', url: `${BASE_URL}/api/users` },
|
||||
{ method: 'GET', url: `${BASE_URL}/api/roles` },
|
||||
{ method: 'GET', url: `${BASE_URL}/api/config` },
|
||||
{ method: 'GET', url: `${BASE_URL}/api/dict` },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'write-operations',
|
||||
weight: 0.3,
|
||||
operations: [
|
||||
{ method: 'POST', url: `${BASE_URL}/api/auth/login`, body: JSON.stringify({ username: 'admin', password: 'admin123' }) },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const scenario = scenarios[Math.random() < 0.7 ? scenarios[0] : scenarios[1]];
|
||||
const operation = scenario.operations[Math.floor(Math.random() * scenario.operations.length)];
|
||||
|
||||
let response;
|
||||
if (operation.method === 'GET') {
|
||||
response = http.get(operation.url, {
|
||||
tags: { name: scenario.name },
|
||||
});
|
||||
} else if (operation.method === 'POST') {
|
||||
response = http.post(operation.url, operation.body, {
|
||||
tags: { name: scenario.name },
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
check(response, {
|
||||
'status is 200 or 201': (r) => r.status === 200 || r.status === 201,
|
||||
'response time < 1s': (r) => r.timings.duration < 1000,
|
||||
'operation successful': (r) => r.status < 400,
|
||||
});
|
||||
|
||||
sleep(Math.random() * 2 + 1);
|
||||
}
|
||||
|
||||
export function teardown(data) {
|
||||
console.log('Concurrent load test completed');
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import http from 'k6/http';
|
||||
import { check, sleep } from 'k6';
|
||||
|
||||
export let options = {
|
||||
stages: [
|
||||
{ duration: '30s', target: 5 },
|
||||
{ duration: '1m', target: 10 },
|
||||
{ duration: '30s', target: 0 },
|
||||
],
|
||||
thresholds: {
|
||||
http_req_duration: ['p(95)<200'],
|
||||
http_req_failed: ['rate<0.01'],
|
||||
},
|
||||
};
|
||||
|
||||
const BASE_URL = __ENV.BASE_URL || 'http://localhost:8084';
|
||||
|
||||
export function setup() {
|
||||
console.log('Starting database performance test...');
|
||||
console.log(`Base URL: ${BASE_URL}`);
|
||||
}
|
||||
|
||||
export default function () {
|
||||
const dbOperations = [
|
||||
{ name: 'get-users', url: `${BASE_URL}/api/users` },
|
||||
{ name: 'get-roles', url: `${BASE_URL}/api/roles` },
|
||||
{ name: 'get-config', url: `${BASE_URL}/api/config` },
|
||||
{ name: 'get-dict', url: `${BASE_URL}/api/dict` },
|
||||
{ name: 'get-logs', url: `${BASE_URL}/api/oplog` },
|
||||
];
|
||||
|
||||
const operation = dbOperations[Math.floor(Math.random() * dbOperations.length)];
|
||||
|
||||
const response = http.get(operation.url, {
|
||||
tags: { name: operation.name },
|
||||
});
|
||||
|
||||
check(response, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 200ms': (r) => r.timings.duration < 200,
|
||||
'data retrieved successfully': (r) => r.body.length > 0,
|
||||
});
|
||||
|
||||
sleep(0.5);
|
||||
}
|
||||
|
||||
export function teardown(data) {
|
||||
console.log('Database performance test completed');
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import http from 'k6/http';
|
||||
import { check, sleep } from 'k6';
|
||||
|
||||
export let options = {
|
||||
stages: [
|
||||
{ duration: '30s', target: 5 },
|
||||
{ duration: '1m', target: 10 },
|
||||
{ duration: '30s', target: 0 },
|
||||
],
|
||||
thresholds: {
|
||||
http_req_duration: ['p(95)<2000'],
|
||||
http_req_failed: ['rate<0.02'],
|
||||
},
|
||||
};
|
||||
|
||||
const BASE_URL = __ENV.BASE_URL || 'http://localhost:3001';
|
||||
|
||||
export function setup() {
|
||||
console.log('Starting frontend performance test...');
|
||||
console.log(`Base URL: ${BASE_URL}`);
|
||||
}
|
||||
|
||||
export default function () {
|
||||
const pages = [
|
||||
'/',
|
||||
'/login',
|
||||
'/dashboard',
|
||||
'/system/config',
|
||||
'/system/dict',
|
||||
'/system/notice',
|
||||
'/oplog',
|
||||
'/loginlog',
|
||||
'/files',
|
||||
];
|
||||
|
||||
const page = pages[Math.floor(Math.random() * pages.length)];
|
||||
const url = `${BASE_URL}${page}`;
|
||||
|
||||
const response = http.get(url, {
|
||||
tags: { name: page },
|
||||
});
|
||||
|
||||
check(response, {
|
||||
'status is 200': (r) => r.status === 200,
|
||||
'response time < 2s': (r) => r.timings.duration < 2000,
|
||||
'page loads successfully': (r) => r.body.length > 0,
|
||||
});
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
export function teardown(data) {
|
||||
console.log('Frontend performance test completed');
|
||||
}
|
||||
Reference in New Issue
Block a user