const { Subscription, Node } = require('./src/models'); const MultiSubscriptionManager = require('./src/core/multiSubscriptionManager'); async function testAutoSpeedTest() { try { console.log('=== 自动测速功能测试 ==='); // 创建测试订阅 const testSubscription = await Subscription.create({ name: '自动测速测试订阅', url: 'http://so.xfxssr.me/api/v1/client/subscribe?token=7854d59f38ac51700730b9e782c5160c', description: '用于测试自动测速功能的订阅', speedTestConfig: { testCount: 3, timeout: 10000, testUrls: ['https://www.google.com'], speedTestEnabled: true }, notifyConfig: { enabled: true, notifyOnSpeedTest: true, notifyOnNodeUpdate: true, webhookUrl: '', emailConfig: null } }); console.log('✅ 创建测试订阅成功'); // 创建多订阅管理器 const manager = new MultiSubscriptionManager(); // 设置测速触发器(模拟) let speedTestTriggered = false; manager.setSpeedTestTrigger(() => { console.log('🚀 测速触发器被调用!'); speedTestTriggered = true; }); // 模拟一些测试节点 console.log('\n2. 创建测试节点...'); const testNodes = [ { name: '自动测速节点1', type: 'ss', server: 'auto1.example.com', port: 443, method: 'aes-256-gcm', password: 'password1', subscriptionId: testSubscription.id }, { name: '自动测速节点2', type: 'ss', server: 'auto2.example.com', port: 443, method: 'aes-256-gcm', password: 'password2', subscriptionId: testSubscription.id }, { name: '自动测速节点3', type: 'ss', server: 'auto3.example.com', port: 443, method: 'aes-256-gcm', password: 'password3', subscriptionId: testSubscription.id } ]; for (const nodeData of testNodes) { await Node.create({ ...nodeData, isActive: true, status: 'offline' }); } console.log(`✅ 创建了 ${testNodes.length} 个测试节点`); // 更新订阅的节点数量 await testSubscription.update({ nodeCount: testNodes.length, lastUpdateTime: new Date() }); // 直接测试触发器功能 console.log('\n3. 直接测试测速触发器...'); manager.triggerSpeedTest(); // 等待触发器执行 await new Promise(resolve => setTimeout(resolve, 1000)); // 检查触发器是否被调用 console.log('\n4. 检查触发器状态...'); if (speedTestTriggered) { console.log('✅ 自动测速功能正常!'); } else { console.log('❌ 自动测速功能未触发'); } // 清理测试数据 console.log('\n5. 清理测试数据...'); await testSubscription.destroy(); console.log('✅ 测试数据清理完成'); console.log('\n=== 自动测速功能测试完成 ==='); } catch (error) { console.error('❌ 测试失败:', error.message); console.error(error.stack); } } // 运行测试 testAutoSpeedTest();