forked from mtusi2026/mtusi2026lab2
lab2: postgres, redis sessions, persistence, EXPLAIN and tests
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import subprocess
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'tests')))
|
||||
from client import Client, Failure
|
||||
|
||||
def main():
|
||||
print("Stopping Redis...")
|
||||
# stdout и stderr в DEVNULL, чтобы PowerShell не ругался на вывод Docker
|
||||
subprocess.run(["docker", "compose", "stop", "redis"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
time.sleep(2)
|
||||
|
||||
c = Client()
|
||||
try:
|
||||
# Пытаемся получить профиль с фейковым токеном.
|
||||
# Так как Redis лежит, сервер должен попытаться прочитать сессию,
|
||||
# поймать ошибку RedisError и вернуть 503, а не упасть с 500.
|
||||
c.call('GET', '/api/v1/users/me', 503, headers={'Authorization': 'Bearer fake_token'})
|
||||
print("PASS: Redis is down, API correctly returned 503")
|
||||
except Failure as e:
|
||||
print(f"FAIL: {e}")
|
||||
sys.exit(1)
|
||||
finally:
|
||||
print("Starting Redis back...")
|
||||
subprocess.run(["docker", "compose", "start", "redis"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user