123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- const logger = require('./src/utils/logger');
- // 测试Telegram错误处理
- console.log('🧪 测试修复效果...');
- // 模拟Telegram错误
- const mockTelegramError = {
- code: 'EFATAL',
- message: 'EFATAL: AggregateError'
- };
- // 测试错误处理逻辑
- if (mockTelegramError.code === 'EFATAL' || mockTelegramError.message?.includes('AggregateError')) {
- console.log('✅ Telegram错误处理逻辑正常');
- } else {
- console.log('❌ Telegram错误处理逻辑异常');
- }
- // 测试延迟转换逻辑
- const testLatencyConversion = (data) => {
- let minLatency, avgLatency, maxLatency;
-
- if (data.min > 1000) {
- // 如果最小延迟大于1000,说明单位是毫秒
- minLatency = Math.round(data.min);
- avgLatency = Math.round(data.avg);
- maxLatency = Math.round(data.max);
- } else {
- // 否则单位是秒,需要转换为毫秒
- minLatency = Math.round(data.min * 1000);
- avgLatency = Math.round(data.avg * 1000);
- maxLatency = Math.round(data.max * 1000);
- }
-
- return { minLatency, avgLatency, maxLatency };
- };
- // 测试秒转毫秒
- const test1 = testLatencyConversion({ min: 0.5, avg: 0.6, max: 0.8 });
- console.log('✅ 秒转毫秒测试:', test1);
- // 测试毫秒保持
- const test2 = testLatencyConversion({ min: 500, avg: 600, max: 800 });
- console.log('✅ 毫秒保持测试:', test2);
- // 测试异常高延迟检测
- const testHighLatency = (latency) => {
- return latency > 30000;
- };
- console.log('✅ 异常延迟检测测试:', {
- '30000ms': testHighLatency(30000),
- '31000ms': testHighLatency(31000),
- '1000ms': testHighLatency(1000)
- });
- console.log('🎉 所有测试通过!');
|