Lab3 - оценка 5
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import collections
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[2] / 'tests'))
|
||||
from client import Client
|
||||
|
||||
|
||||
def containers():
|
||||
out = subprocess.run(['docker', 'ps', '--filter', 'label=com.docker.compose.service=api',
|
||||
'--format', '{{.ID}} {{.Names}}'], capture_output=True, text=True).stdout
|
||||
return dict(line.split(' ', 1) for line in out.split('\n') if line.strip())
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument('--base-url', default='http://localhost:8080')
|
||||
p.add_argument('--n', type=int, default=10)
|
||||
a = p.parse_args()
|
||||
c = Client(a.base_url)
|
||||
user = c.user('demo')
|
||||
print('Пользователь %s вошёл ОДИН раз (токен не печатается).' % user['user']['username'])
|
||||
names = containers()
|
||||
seen = collections.Counter()
|
||||
for i in range(1, a.n + 1):
|
||||
r = c.call('GET', '/api/v1/users/me', actor=user, schema='User')
|
||||
iid = r['headers']['X-Instance-Id']
|
||||
seen[iid] += 1
|
||||
print('запрос %2d -> 200, X-Instance-Id=%s (контейнер %s)' % (i, iid, names.get(iid, '?')))
|
||||
print('Итого: %d разных реплик обслужили одну сессию: %s' % (len(seen), dict(seen)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user