Keep distinct proxy accounts and rotate the tail of the list
CI / Python 3.13 (push) Successful in 52s
CI / Python 3.12 (push) Successful in 1m4s
CI / Build and smoke-test image (push) Successful in 12s

This commit is contained in:
omar committed 2026-11-28 19:30:11 +03:00
1 parent dbcd91eae0
commit d9ab6ad229
6 files changed
+45 -4

No files matched your search

+21
View File
@@ -85,3 +85,24 @@ def test_inventory_interval_rejects_invalid_values(monkeypatch, value):
monkeypatch.setenv('MCP_PROXY_LIST_REFRESH_MINUTES', value)
with pytest.raises(ValueError, match='MCP_PROXY_LIST_REFRESH_MINUTES'):
Settings.load()
def test_accounts_on_one_gateway_are_distinct_routes(monkeypatch):
monkeypatch.setenv('MCP_PROXY_URLS', '["http://a:1@10.0.0.1:8081", "http://a:2@10.0.0.1:8081"]')
assert Settings.load().proxies == ('http://a:1@10.0.0.1:8081', 'http://a:2@10.0.0.1:8081')
def test_same_credentials_on_one_gateway_are_a_duplicate(monkeypatch):
monkeypatch.setenv('MCP_PROXY_URLS', '["http://a:1@10.0.0.1:8081", "http://a:1@10.0.0.1:8081"]')
with pytest.raises(ValueError):
Settings.load()
def test_proxy_list_limit_bounds(monkeypatch):
for value, ok in (('1', True), ('1024', True), ('0', False), ('1025', False), ('', False)):
monkeypatch.setenv('MCP_PROXY_LIST_LIMIT', value)
if ok:
assert Settings.load().proxy_list_limit == int(value)
else:
with pytest.raises(ValueError):
Settings.load()
+10
View File
@@ -1,4 +1,5 @@
import asyncio
import re
from contextlib import asynccontextmanager
from dataclasses import replace
@@ -97,3 +98,12 @@ async def test_periodic_refresh_keeps_last_success_then_recovers(tmp_path, monke
await refresh_proxy_list(cfg, install)
assert delays == [420] * 4
assert installed == [('http://first',), ('https://second',)]
@pytest.mark.anyio
async def test_only_the_trailing_limit_entries_are_kept(monkeypatch):
body = b''.join(f'http://user{i}:pass@10.0.0.1:8081\n'.encode() for i in range(5))
async with inventory(body) as (url, _calls):
cfg = Settings(None, proxy_list_url=url, proxy_list_token='fixture-token', proxy_list_limit=2)
kept = await fetch_proxy_list(cfg)
assert [re.search(r'user([0-9]+)', item)[1] for item in kept] == ['3', '4']