fix: 失效超过三十分钟的代理会重新检测
This commit is contained in:
@@ -191,6 +191,35 @@ def test_failed_proxy_is_not_reprobed(monkeypatch) -> None:
|
||||
assert node.status == "dead"
|
||||
|
||||
|
||||
def test_old_dead_proxy_is_reprobed(monkeypatch) -> None:
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
_holds.clear()
|
||||
stale = _node("8.8.8.8", 88, status="dead")
|
||||
with SessionLocal() as db:
|
||||
node = db.get(ProxyNode, stale.id)
|
||||
assert node is not None
|
||||
node.last_checked_at = datetime.now(timezone.utc) - timedelta(hours=1)
|
||||
db.commit()
|
||||
monkeypatch.setattr(
|
||||
"euniv.proxy_pool.collect_all",
|
||||
lambda: [ProxyCandidate("http", "8.8.8.8", 88, "cn", "elite", "proxyhub")],
|
||||
)
|
||||
called: list[str] = []
|
||||
|
||||
def fake_probe(scheme: str, host: str, port: int):
|
||||
called.append(host)
|
||||
return True, 20, ""
|
||||
|
||||
monkeypatch.setattr("euniv.proxy_pool.probe", fake_probe)
|
||||
refresh_once()
|
||||
assert called == ["8.8.8.8"]
|
||||
with SessionLocal() as db:
|
||||
node = db.get(ProxyNode, stale.id)
|
||||
assert node is not None
|
||||
assert node.status == "alive"
|
||||
|
||||
|
||||
def test_probe_averages_euniv_related_sites(monkeypatch) -> None:
|
||||
seen: list[str] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user