fix: 代理瞬时失败显示真实延迟和原因
This commit is contained in:
@@ -219,6 +219,29 @@ def test_probe_averages_euniv_related_sites(monkeypatch) -> None:
|
||||
assert reason == ""
|
||||
|
||||
|
||||
def test_probe_instant_connect_error_keeps_elapsed_latency(monkeypatch) -> None:
|
||||
class FakeClient:
|
||||
def __init__(self, **_kwargs) -> None:
|
||||
return None
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *_args) -> bool:
|
||||
return False
|
||||
|
||||
def get(self, _url: str):
|
||||
raise httpx.ConnectError("boom")
|
||||
|
||||
ticks = iter([0.0, 0.012, 0.012, 0.018, 0.018, 0.025])
|
||||
monkeypatch.setattr("euniv.proxy_pool.httpx.Client", FakeClient)
|
||||
monkeypatch.setattr("euniv.proxy_pool.time.perf_counter", lambda: next(ticks))
|
||||
ok, latency, reason = probe("socks4", "10.0.0.9", 1080)
|
||||
assert ok is False
|
||||
assert latency == 8
|
||||
assert reason == "无法连接"
|
||||
|
||||
|
||||
def test_admin_can_probe_one_and_all_proxies(monkeypatch) -> None:
|
||||
import euniv.api as api_module
|
||||
|
||||
|
||||
Reference in New Issue
Block a user