()
| 40 | } |
| 41 | |
| 42 | export function useBatchLatencyTest() { |
| 43 | const configStore = useConfigStore() |
| 44 | const proxiesStore = useProxiesStore() |
| 45 | const nodeRecommendationStore = useNodeRecommendationStore() |
| 46 | const { t } = useI18n() |
| 47 | |
| 48 | const isRunning = ref(false) |
| 49 | const progress = ref({ completed: 0, total: 0, current: '' }) |
| 50 | const abortController = ref<AbortController | null>(null) |
| 51 | |
| 52 | // Test a single proxy node |
| 53 | const testSingleNode = async ( |
| 54 | proxyName: string, |
| 55 | url: string, |
| 56 | timeout: number, |
| 57 | signal?: AbortSignal, |
| 58 | ): Promise<{ proxyName: string; delay: number }> => { |
| 59 | try { |
| 60 | const request = useRequest() |
| 61 | const result = await request |
| 62 | .get(`proxies/${encodeURIComponent(proxyName)}/delay`, { |
| 63 | searchParams: { url, timeout }, |
| 64 | signal, |
| 65 | // Client timeout must exceed the backend per-node budget + network |
| 66 | // overhead, else ky aborts a slow-but-valid probe before the kernel |
| 67 | // answers and the node always reads as failed (#2041). |
| 68 | timeout: Math.max(20_000, timeout + 10_000), |
| 69 | }) |
| 70 | .json<{ delay: number }>() |
| 71 | return { proxyName, delay: result.delay } |
| 72 | } catch { |
| 73 | return { proxyName, delay: 0 } // 0 indicates failure |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Test a proxy group (uses backend batch API) |
| 78 | const testProxyGroup = async ( |
| 79 | groupName: string, |
| 80 | url: string, |
| 81 | timeout: number, |
| 82 | ): Promise<Record<string, number>> => { |
| 83 | try { |
| 84 | const request = useRequest() |
| 85 | const result = await request |
| 86 | .get(`group/${encodeURIComponent(groupName)}/delay`, { |
| 87 | searchParams: { url, timeout }, |
| 88 | // The backend timeout is per-node; the group test fans out to every |
| 89 | // member, so the overall round trip easily exceeds ky's 5s default. |
| 90 | // Scale the client timeout generously, floored at 30s, plus 10s of |
| 91 | // headroom. |
| 92 | timeout: Math.max(30_000, timeout * 2 + 10_000), |
| 93 | }) |
| 94 | .json<Record<string, number>>() |
| 95 | return result |
| 96 | } catch { |
| 97 | return {} |
| 98 | } |
| 99 | } |
no outgoing calls
no test coverage detected