develop #2

Merged
jenkins merged 49 commits from develop into main 2026-04-08 19:55:46 +08:00
Showing only changes of commit 3e6b2ac057 - Show all commits
+133 -7
View File
@@ -27,16 +27,51 @@ async function checkBackendHealth(): Promise<boolean> {
} }
} }
async function checkGatewayHealth(): Promise<boolean> {
try {
const response = await fetch('http://localhost:8080/actuator/health', {
signal: AbortSignal.timeout(5000)
} as any);
if (response.ok) {
const data = await response.json();
return data.status === 'UP';
}
return false;
} catch (error) {
return false;
}
}
async function checkFrontendHealth(): Promise<boolean> {
try {
const response = await fetch('http://localhost:3002', {
signal: AbortSignal.timeout(5000)
} as any);
return response.ok;
} catch (error) {
return false;
}
}
function startHealthMonitoring() { function startHealthMonitoring() {
if (healthCheckInterval) { if (healthCheckInterval) {
clearInterval(healthCheckInterval); clearInterval(healthCheckInterval);
} }
healthCheckInterval = setInterval(async () => { healthCheckInterval = setInterval(async () => {
const isHealthy = await checkBackendHealth(); const backendHealthy = await checkBackendHealth();
if (!isHealthy) { const gatewayHealthy = await checkGatewayHealth();
const frontendHealthy = await checkFrontendHealth();
if (!backendHealthy) {
console.error('⚠️ 后端服务健康检查失败!'); console.error('⚠️ 后端服务健康检查失败!');
} }
if (!gatewayHealthy) {
console.error('⚠️ 网关服务健康检查失败!');
}
if (!frontendHealthy) {
console.error('⚠️ 前端服务健康检查失败!');
}
}, 30000); }, 30000);
} }
@@ -228,6 +263,9 @@ async function globalSetup(config: FullConfig) {
console.log('⏳ 等待前端服务就绪...'); console.log('⏳ 等待前端服务就绪...');
await waitForFrontendReady(); await waitForFrontendReady();
console.log('🔍 验证所有服务连通性...');
await verifyAllServices();
console.log('🧹 清理测试数据...'); console.log('🧹 清理测试数据...');
await cleanupTestData(); await cleanupTestData();
@@ -236,18 +274,86 @@ async function globalSetup(config: FullConfig) {
console.log('✅ 全局测试环境设置完成'); console.log('✅ 全局测试环境设置完成');
} }
async function verifyAllServices(): Promise<void> {
console.log(' 验证后端服务...');
const backendOk = await checkBackendHealth();
if (!backendOk) {
throw new Error('❌ 后端服务验证失败');
}
console.log(' ✅ 后端服务正常');
console.log(' 验证网关服务...');
const gatewayOk = await checkGatewayHealth();
if (!gatewayOk) {
throw new Error('❌ 网关服务验证失败');
}
console.log(' ✅ 网关服务正常');
console.log(' 验证前端服务...');
const frontendOk = await checkFrontendHealth();
if (!frontendOk) {
throw new Error('❌ 前端服务验证失败');
}
console.log(' ✅ 前端服务正常');
console.log(' 验证网关到后端的连通性...');
try {
const response = await fetch('http://localhost:8080/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: 'admin', password: 'admin123' }),
signal: AbortSignal.timeout(10000) as any
});
if (!response.ok) {
throw new Error(`网关到后端连通性验证失败,状态码: ${response.status}`);
}
const data = await response.json();
if (!data.token) {
throw new Error('网关到后端连通性验证失败,未返回token');
}
console.log(' ✅ 网关到后端连通性正常');
} catch (error) {
throw new Error(`❌ 网关到后端连通性验证失败: ${error}`);
}
console.log('✅ 所有服务验证通过');
}
async function waitForBackendReady(): Promise<void> { async function waitForBackendReady(): Promise<void> {
const maxRetries = 60; const maxRetries = 90;
const retryInterval = 1000; const retryInterval = 1000;
for (let i = 0; i < maxRetries; i++) { for (let i = 0; i < maxRetries; i++) {
try { try {
const response = await fetch('http://localhost:8084/actuator/health'); const response = await fetch('http://localhost:8084/actuator/health', {
signal: AbortSignal.timeout(5000) as any
});
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
if (data.status === 'UP') { if (data.status === 'UP') {
console.log(`✅ 后端服务健康检查通过 (尝试 ${i + 1}/${maxRetries})`); console.log(`✅ 后端服务健康检查通过 (尝试 ${i + 1}/${maxRetries})`);
// 验证服务连通性:测试登录API
try {
const loginTest = await fetch('http://localhost:8084/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: 'admin', password: 'admin123' }),
signal: AbortSignal.timeout(10000) as any
});
if (loginTest.ok) {
console.log('✅ 后端服务连通性验证通过(登录API可用)');
return; return;
} else {
console.log(`⚠️ 后端服务连通性验证失败,状态码: ${loginTest.status}`);
}
} catch (error) {
console.log('⚠️ 后端服务连通性验证失败,继续等待...');
}
} }
} }
} catch (error) { } catch (error) {
@@ -263,17 +369,37 @@ async function waitForBackendReady(): Promise<void> {
} }
async function waitForGatewayReady(): Promise<void> { async function waitForGatewayReady(): Promise<void> {
const maxRetries = 60; const maxRetries = 90;
const retryInterval = 1000; const retryInterval = 1000;
for (let i = 0; i < maxRetries; i++) { for (let i = 0; i < maxRetries; i++) {
try { try {
const response = await fetch('http://localhost:8080/actuator/health'); const response = await fetch('http://localhost:8080/actuator/health', {
signal: AbortSignal.timeout(5000) as any
});
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
if (data.status === 'UP') { if (data.status === 'UP') {
console.log(`✅ 网关服务健康检查通过 (尝试 ${i + 1}/${maxRetries})`); console.log(`✅ 网关服务健康检查通过 (尝试 ${i + 1}/${maxRetries})`);
// 验证网关连通性:通过网关测试登录API
try {
const loginTest = await fetch('http://localhost:8080/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: 'admin', password: 'admin123' }),
signal: AbortSignal.timeout(10000) as any
});
if (loginTest.ok) {
console.log('✅ 网关服务连通性验证通过(登录API可用)');
return; return;
} else {
console.log(`⚠️ 网关服务连通性验证失败,状态码: ${loginTest.status}`);
}
} catch (error) {
console.log('⚠️ 网关服务连通性验证失败,继续等待...');
}
} }
} }
} catch (error) { } catch (error) {
@@ -289,7 +415,7 @@ async function waitForGatewayReady(): Promise<void> {
} }
async function waitForFrontendReady(): Promise<void> { async function waitForFrontendReady(): Promise<void> {
const maxRetries = 60; const maxRetries = 90;
const retryInterval = 1000; const retryInterval = 1000;
for (let i = 0; i < maxRetries; i++) { for (let i = 0; i < maxRetries; i++) {