Files
mtusi2026lab2/evidence/auth-retest-2026-10-13-658e0bd7/run-suites.py
T
OlegRood 834876c938 ЛР 2: закрыть уровень 4
Завершить PostgreSQL, Redis-сессии, миграции, таймауты и диагностику. Зафиксировать собственные тесты и доказательства финального прогона: 43 PASS, 0 FAIL, 0 SKIP; 768 HTTP-запросов без ошибок. Добавить официальный отчёт с запуском, архитектурой, SQL-планами и ограничениями. PR отложен до завершения уровня 5.
2026-10-28 13:30:26 +03:00

43 lines
2.8 KiB
Python

import json,os,pathlib,subprocess,time,urllib.request,urllib.error
s=json.loads(pathlib.Path('/tmp/highload-current-auth-retest.json').read_text());root=pathlib.Path(s['root']);tmp=pathlib.Path(s['tmp'])
assert s['project'].startswith('highload-auth-retest-')
base=['docker','compose','-p',s['project'],'--project-directory',str(root),'-f',str(root/'compose.yaml'),'-f',str(tmp/'compose.test.yaml')]
results=[]
def run(args,label,env=None):
try:
p=subprocess.run(args,cwd=root,env=env,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True,timeout=180)
code=p.returncode;out=p.stdout
except subprocess.TimeoutExpired:
code=124;out='Test command exceeded 180 seconds; results incomplete.\n'
(tmp/(label+'.log')).write_text(out)
result={'check':label,'exit_code':code,'status':'PASS' if code==0 else 'FAIL'}
results.append(result);print(label+': '+result['status'],flush=True)
(tmp/'suite-summary.json').write_text(json.dumps(results,indent=2))
return code
def ready(url):
deadline=time.monotonic()+45
while True:
try:
with urllib.request.urlopen(url+'/health/ready',timeout=3) as response:
if response.status==200:return
except (OSError,urllib.error.URLError):pass
if time.monotonic()>deadline:raise RuntimeError('test API not ready')
time.sleep(.2)
ready(s['base_url'])
env=os.environ.copy();db='postgres://messenger:'+(tmp/'postgres_password').read_text()+'@127.0.0.1:'+str(s['pg_port'])+'/messenger?sslmode=disable'
env['AUTH_TEST_DATABASE_URL']=db;env['MIGRATE_TEST_DATABASE_URL']=db
run(['make','check'],'teacher-check')
run(['make','validate','PYTHON=/tmp/highload-auth-review-venv/bin/python'],'teacher-openapi')
run(['go','test','-race','./...','-count=1','-json'],'go-all-race',env)
run(['make','test','BASE_URL='+s['base_url']],'teacher-smoke')
run(['python3','student-tests/auth_contract.py','--base-url',s['base_url'],'--ttl','3600'],'auth-normal')
run(['make','test-persistence','BASE_URL='+s['base_url'],'ACTION_SCRIPT='+str(tmp/'test-restart')],'teacher-persistence')
run(['python3','student-tests/auth_contract.py','--suite','persistence','--base-url',s['base_url'],'--ttl','3600','--restart-hook',str(tmp/'test-restart'),'--hook-timeout','60'],'auth-persistence')
run(['python3','student-tests/auth_contract.py','--suite','dependency','--dependency','postgres','--base-url',s['base_url'],'--ttl','3600','--failure-hook',str(tmp/'test-failure'),'--recovery-hook',str(tmp/'test-recovery'),'--hook-timeout','60','--timeout','5'],'auth-dependency')
# Same newly built API image, separate process with short TTL.
if run(base+['up','-d','--no-build','api_expiry'],'start-expiry-api')==0:
ready(s['expiry_url'])
run(['python3','student-tests/auth_contract.py','--suite','expiry','--base-url',s['expiry_url'],'--ttl','2'],'auth-expiry')
print('Suites completed; keep disposable project for focused diagnostics.',flush=True)