test-fixes.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const logger = require('./src/utils/logger');
  2. // 测试Telegram错误处理
  3. console.log('🧪 测试修复效果...');
  4. // 模拟Telegram错误
  5. const mockTelegramError = {
  6. code: 'EFATAL',
  7. message: 'EFATAL: AggregateError'
  8. };
  9. // 测试错误处理逻辑
  10. if (mockTelegramError.code === 'EFATAL' || mockTelegramError.message?.includes('AggregateError')) {
  11. console.log('✅ Telegram错误处理逻辑正常');
  12. } else {
  13. console.log('❌ Telegram错误处理逻辑异常');
  14. }
  15. // 测试延迟转换逻辑
  16. const testLatencyConversion = (data) => {
  17. let minLatency, avgLatency, maxLatency;
  18. if (data.min > 1000) {
  19. // 如果最小延迟大于1000,说明单位是毫秒
  20. minLatency = Math.round(data.min);
  21. avgLatency = Math.round(data.avg);
  22. maxLatency = Math.round(data.max);
  23. } else {
  24. // 否则单位是秒,需要转换为毫秒
  25. minLatency = Math.round(data.min * 1000);
  26. avgLatency = Math.round(data.avg * 1000);
  27. maxLatency = Math.round(data.max * 1000);
  28. }
  29. return { minLatency, avgLatency, maxLatency };
  30. };
  31. // 测试秒转毫秒
  32. const test1 = testLatencyConversion({ min: 0.5, avg: 0.6, max: 0.8 });
  33. console.log('✅ 秒转毫秒测试:', test1);
  34. // 测试毫秒保持
  35. const test2 = testLatencyConversion({ min: 500, avg: 600, max: 800 });
  36. console.log('✅ 毫秒保持测试:', test2);
  37. // 测试异常高延迟检测
  38. const testHighLatency = (latency) => {
  39. return latency > 30000;
  40. };
  41. console.log('✅ 异常延迟检测测试:', {
  42. '30000ms': testHighLatency(30000),
  43. '31000ms': testHighLatency(31000),
  44. '1000ms': testHighLatency(1000)
  45. });
  46. console.log('🎉 所有测试通过!');