tests: полный вывод сценариев, ключи mc ls, разбивка времени reconciler
This commit is contained in:
@@ -144,9 +144,14 @@ def scenario_db_gap(c):
|
||||
check(objs == '0', 'compensation must delete the object, objects=' + objs)
|
||||
# Reconciler (короткий grace для теста) убирает брошенное намерение.
|
||||
psql("UPDATE attachments SET updated_at = now() - interval '30 minutes' WHERE chat_id = '%s'" % chat['id'])
|
||||
out = compose('run', '--rm', '--no-deps', '-T', '--entrypoint', '/app/reconcile', 'reconciler',
|
||||
'--apply', '--grace', '10m').stdout.strip().splitlines()[-1]
|
||||
rep = json.loads(out)
|
||||
for _ in range(10):
|
||||
r = compose('run', '--rm', '--no-deps', '-T', '--entrypoint', '/app/reconcile', 'reconciler',
|
||||
'--apply', '--grace', '10m', check=False)
|
||||
if r.returncode != 3: # 3 — advisory lock у фонового reconciler
|
||||
break
|
||||
time.sleep(2)
|
||||
check(r.returncode in (0, 4), 'reconcile failed: ' + r.stderr[-300:])
|
||||
rep = json.loads(r.stdout.strip().splitlines()[-1])
|
||||
after = psql("SELECT count(*) FROM attachments WHERE chat_id = '%s'" % chat['id'])
|
||||
check(after == '0', 'reconciler did not remove stale intent')
|
||||
return {'client_status': st, 'seconds': round(time.time() - t0, 1), 'after_gap': {'rows': rows.split()[-1], 'objects': int(objs)},
|
||||
@@ -172,7 +177,7 @@ def scenario_security(c):
|
||||
check(own == 'ok', 'api key cannot read own bucket')
|
||||
check(mb.returncode != 0, 'api key must not create buckets')
|
||||
check(admin.returncode != 0, 'api key must not use admin API')
|
||||
check(buckets.returncode != 0 or BUCKET not in buckets.stdout or 'evil' not in buckets.stdout, 'unexpected bucket listing')
|
||||
check(buckets.returncode != 0 or 'evil' not in buckets.stdout, 'api key sees a bucket it created?!')
|
||||
# Bootstrap идемпотентен: повторный запуск успешен, объект на месте.
|
||||
before = mc('mc ls --recursive s3/%s | wc -l' % BUCKET).stdout.strip()
|
||||
r1 = compose('run', '--rm', 's3-init')
|
||||
@@ -183,7 +188,8 @@ def scenario_security(c):
|
||||
check('0.0.0.0' not in ports and '127.0.0.1' not in ports, 's3 port is published: ' + ports)
|
||||
return {'anonymous_get': '403', 'anonymous_list': '403', 'api_key_own_bucket': 'allowed',
|
||||
'api_key_make_bucket': 'denied', 'api_key_admin': 'denied',
|
||||
'api_key_list_all_buckets': 'denied' if buckets.returncode != 0 else 'allowed',
|
||||
'api_key_visible_buckets': sorted(l.split()[-1].rstrip('/') for l in buckets.stdout.splitlines() if l.strip())
|
||||
if buckets.returncode == 0 else 'denied',
|
||||
'bootstrap_runs': [r1.returncode, r2.returncode], 'objects_before_after': [int(before), int(after)],
|
||||
's3_published_ports': ports or 'none'}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ def main():
|
||||
'duration_ms_runs': ms, 'duration_ms_median': statistics.median(ms),
|
||||
'us_per_pair': round(1000 * statistics.median(ms) / max(1, r['rows_scanned']), 1),
|
||||
'calls': r['calls'], 'heap_alloc_mb': r['heap_alloc_mb'], 'found': r['found'],
|
||||
'wait_ms_runs': [x.get('wait_ms') for x in reps],
|
||||
'seed_seconds': round(seed_s, 1)})
|
||||
print(json.dumps(runs[-1], ensure_ascii=False))
|
||||
# 1% расхождений на самом большом наборе: удалённые объекты и сироты.
|
||||
|
||||
@@ -44,7 +44,9 @@ def snapshot(chat_id):
|
||||
rows = psql("SELECT id || ':' || status || ':' || COALESCE(size_bytes, 0) FROM attachments "
|
||||
"WHERE chat_id = '%s' ORDER BY id" % chat_id)
|
||||
objs = mc('mc ls --recursive --json s3/%s/a/%s/' % (BUCKET, chat_id)).stdout
|
||||
keys = sorted((json.loads(l)['key'], json.loads(l)['size']) for l in objs.splitlines() if l.strip())
|
||||
# mc ls --json отдаёт key относительно листинга — дополняем до полного ключа.
|
||||
keys = sorted(('a/%s/%s' % (chat_id, json.loads(l)['key']), json.loads(l)['size'])
|
||||
for l in objs.splitlines() if l.strip() and 'key' in json.loads(l))
|
||||
return rows, keys
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user