Implement lab3 grade 4: balanced API replicas, shared idempotency and failure tests
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Short defense demonstration, with tokens and credentials kept only in memory."""
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
|
||||
from client import Client, check
|
||||
|
||||
c = Client(os.environ.get('BASE_URL', 'http://127.0.0.1:8080'))
|
||||
alice, bob, eve, chat = c.bootstrap()
|
||||
instances = Counter(c.call('GET', '/api/v1/users/me', actor=alice, schema='User')['headers']['X-Instance-Id']
|
||||
for _ in range(12))
|
||||
check(len(instances) == 2, 'Two API instances must serve the same session')
|
||||
print('One login; 12 requests through LB:')
|
||||
for instance, count in sorted(instances.items()):
|
||||
print(' ', instance, ':', count, 'requests')
|
||||
key = uuid.uuid4().hex
|
||||
first = c.message(alice, chat, 'Одно сообщение при двух повторах', key=key)
|
||||
second = c.message(alice, chat, 'Одно сообщение при двух повторах', key=key)
|
||||
check(first['json'] == second['json'], 'Replay differs')
|
||||
print('POST #1:', first['status'], first['headers']['X-Instance-Id'])
|
||||
print('POST #2:', second['status'], second['headers']['X-Instance-Id'])
|
||||
print('Same message ID:', first['json']['id'])
|
||||
print('PASS: shared session, different processes, one message.')
|
||||
Reference in New Issue
Block a user