latency-probe.py

import importlib.util,sys,time,json,socket,asyncio
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch
attempts=[]
def deny(*a,**kw):attempts.append('network');raise AssertionError('offline')
socket.socket.connect=deny;socket.getaddrinfo=deny
spec=importlib.util.spec_from_file_location('fixture_health','/tmp/fr21-current-review/test_health.py');m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m);m.SOURCE=Path('/tmp/fr21-current-review/Cell1.py')
calls=[]
def delayed(**kwargs):
 calls.append(kwargs);time.sleep(2.6);return iter(())
start=time.monotonic();response=m.request(db=SimpleNamespace(collections=delayed),bucket=SimpleNamespace(list_blobs=delayed),project='fixture',bucket_name='fixture');elapsed=time.monotonic()-start
assert elapsed>5 and response.status_code==200
spec=importlib.util.spec_from_file_location('gateway_fixture','/tmp/fr21-current-review/main-production.py');g=importlib.util.module_from_spec(spec);spec.loader.exec_module(g)
g.SERVICE_REGISTRY={'/api/v1/cell1':'http://fixture.invalid'}
class Client:
 def __init__(self,*a,**k):pass
 async def __aenter__(self):return self
 async def __aexit__(self,*a):pass
 async def get(self,url):return SimpleNamespace(status_code=200,json=lambda:{'status':'degraded','checks':{'firestore':'unhealthy','gcs':'not_configured'}})
with patch.object(g.httpx,'AsyncClient',Client):aggregate=asyncio.run(g.check_all_services())
assert aggregate['healthy_percentage']==100
assert not attempts
Path('/tmp/fr21-current-review/results.json').write_text(json.dumps({'head':'175d20549f38a2a0f195fdec99f4edbfdd0db7ad','scope':'exact extracted Cell1 routes and imported main-production gateway; controlled latency/response doubles; no network','latency':{'elapsed_seconds':elapsed,'probe_deadline_seconds':5,'each_fixture_latency_seconds':2.6,'sdk_arguments':calls,'response':response.json()},'alternate_gateway_degraded_200_result':aggregate,'gateway_build_caveat':'repository Dockerfile runs main:app, not main-production:app; no serving mapping proves alternate gateway is live','network_attempts':attempts},indent=2)+'\n')
print('Sequential health elapsed',round(elapsed,3),'exceeds5-second declared probe; alternate gateway mislabels degraded200 as healthy; deployed consumer identity unverified')
← All docsView source on GitHub →