feat: 立即开始停止学习并整理学时历史与界面

This commit is contained in:
2026-11-15 04:16:40 +08:00
parent ce2d6e08dd
commit f0a2bdd854
25 changed files with 1748 additions and 580 deletions
+52 -1
View File
@@ -7,7 +7,7 @@ from euniv.db import SessionLocal
from euniv.models import Account, ProxyNode
from euniv.proxy import apply as apply_proxy
from euniv.proxy import bind_url, is_proxy_failure, view_of
from euniv.proxy_pool import acquire, mark_failed, page, refresh_once, release
from euniv.proxy_pool import PROBE_URLS, acquire, mark_failed, page, probe, refresh_once, release
from euniv.proxy_pool import _holds
INITIAL_PASSWORD = "242520"
@@ -189,6 +189,57 @@ def test_failed_proxy_is_not_reprobed(monkeypatch) -> None:
assert node.status == "dead"
def test_probe_averages_euniv_related_sites(monkeypatch) -> None:
seen: list[str] = []
class FakeResponse:
status_code = 200
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):
seen.append(url)
return FakeResponse()
ticks = iter([0.0, 0.12, 0.12, 0.34, 0.34, 0.64])
monkeypatch.setattr("euniv.proxy_pool.httpx.Client", FakeClient)
monkeypatch.setattr("euniv.proxy_pool.time.perf_counter", lambda: next(ticks))
ok, latency, reason = probe("http", "10.0.0.9", 8080)
assert seen == list(PROBE_URLS)
assert ok is True
assert latency == 213
assert reason == ""
def test_admin_can_probe_one_and_all_proxies(monkeypatch) -> None:
import euniv.api as api_module
_holds.clear()
one = _node("10.0.0.7", 8007)
two = _node("10.0.0.8", 8008, status="new")
monkeypatch.setattr("euniv.proxy_pool.probe", lambda scheme, host, port: (True, 321 if host.endswith("7") else 654, ""))
client = TestClient(api_module.app)
assert client.post("/api/login", json={"employee_id": "admin", "password": INITIAL_PASSWORD}).status_code == 200
single = client.post(f"/api/admin/proxies/{one.id}/probe")
assert single.status_code == 200
assert single.json()["latency_ms"] == 321
assert single.json()["status"] == "alive"
bulk = client.post("/api/admin/proxies/probe", json={"ids": [two.id]})
assert bulk.status_code == 200
assert bulk.json()["count"] == 1
assert bulk.json()["items"][0]["latency_ms"] == 654
missing = client.post("/api/admin/proxies/99999/probe")
assert missing.status_code == 404
def test_is_proxy_failure_detects_connect_errors() -> None:
assert is_proxy_failure(httpx.ConnectError("boom"))
assert is_proxy_failure(httpx.ConnectTimeout("late"))