forked from mtusi2026/mtusi2026lab4
Проверить ЛР4: сборка MinIO из исходников и результаты полного прогона
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""Stop the exact replica that accepted the upload, then compare original bytes."""
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
|
||||
from client import Client, Failure, check
|
||||
|
||||
c = Client(timeout=10)
|
||||
a, b, _, chat = c.bootstrap()
|
||||
png = (Path(__file__).resolve().parents[1] / 'tests/fixtures/sample.png').read_bytes()
|
||||
result = c.call('POST', '/api/v1/chats/' + chat['id'] + '/attachments?filename=failover.png',
|
||||
201, actor=a, raw=png, headers={'Content-Type': 'image/png'}, schema='Attachment')
|
||||
target = result['headers']['X-Instance-Id']
|
||||
check(target in ('api1', 'api2'), 'unknown upload replica')
|
||||
try:
|
||||
subprocess.run(['docker', 'compose', 'stop', target], check=True)
|
||||
deadline = time.monotonic() + 20
|
||||
while True:
|
||||
try:
|
||||
downloaded = c.call('GET', '/api/v1/attachments/' + result['json']['id'] + '/content', actor=b)
|
||||
break
|
||||
except Failure:
|
||||
if time.monotonic() >= deadline:
|
||||
raise
|
||||
time.sleep(0.5)
|
||||
check(downloaded['headers']['X-Instance-Id'] != target, 'uploader still serves download')
|
||||
check(downloaded['bytes'] == png, 'original changed after uploader stopped')
|
||||
print('PASS: upload=' + target + ', download=' + downloaded['headers']['X-Instance-Id']
|
||||
+ ', sha256=' + hashlib.sha256(png).hexdigest())
|
||||
finally:
|
||||
subprocess.run(['docker', 'compose', 'up', '-d', '--wait', 'api1', 'api2'], check=True)
|
||||
@@ -38,6 +38,12 @@ try:
|
||||
with psycopg.connect(dsn) as db:
|
||||
db.execute("UPDATE attachments SET status='ready' WHERE id=%s", (ids[0],))
|
||||
db.rollback()
|
||||
# Even an old intent must survive while a live finalization holds its lock.
|
||||
with psycopg.connect(dsn) as active:
|
||||
active.execute('SELECT id FROM attachments WHERE id=%s FOR UPDATE', (ids[0],))
|
||||
sweep()
|
||||
storage.client.head_object(Bucket=storage.BUCKET, Key=keys[0])
|
||||
assert active.execute('SELECT status FROM attachments WHERE id=%s', (ids[0],)).fetchone()[0] == 'pending'
|
||||
sweep()
|
||||
sweep() # Idempotent after completion.
|
||||
with psycopg.connect(dsn) as db:
|
||||
@@ -50,7 +56,7 @@ try:
|
||||
assert error.response['ResponseMetadata']['HTTPStatusCode']==404
|
||||
for key in keys[1:]:
|
||||
storage.client.head_object(Bucket=storage.BUCKET,Key=key)
|
||||
print('PASS: private bucket, failed finalization recovery, grace period, ready protection, repeated cleanup')
|
||||
print('PASS: private bucket, failed finalization recovery, active lock protection, grace period, ready protection, repeated cleanup')
|
||||
finally:
|
||||
for key in keys:
|
||||
storage.client.delete_object(Bucket=storage.BUCKET,Key=key)
|
||||
|
||||
+14
-1
@@ -1,11 +1,13 @@
|
||||
"""Black-box grade-4 checks; creates only synthetic data on the local lab."""
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import threading
|
||||
import uuid
|
||||
from PIL import Image
|
||||
from urllib.parse import quote
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
|
||||
from client import Client, check
|
||||
@@ -14,6 +16,17 @@ c = Client(timeout=45)
|
||||
a,b,e,chat = c.bootstrap()
|
||||
base = '/api/v1/chats/' + chat['id']
|
||||
att, png = c.attachment(a, chat)
|
||||
# Exercise the second supported format through both stores, not only Pillow.
|
||||
jpeg_file = io.BytesIO()
|
||||
Image.new('RGB', (320, 200), (20, 30, 40)).save(jpeg_file, 'JPEG')
|
||||
jpeg = jpeg_file.getvalue()
|
||||
jpeg_att = c.call('POST', base+'/attachments?filename=photo.jpg', 201, actor=a,
|
||||
raw=jpeg, headers={'Content-Type': 'image/jpeg'}, schema='Attachment')['json']
|
||||
check(jpeg_att['sha256'] == hashlib.sha256(jpeg).hexdigest(), 'JPEG checksum differs')
|
||||
check(jpeg_att['size_bytes'] == len(jpeg), 'JPEG length differs')
|
||||
jpeg_download = c.call('GET', '/api/v1/attachments/'+jpeg_att['id']+'/content', actor=b)
|
||||
check(jpeg_download['bytes'] == jpeg, 'JPEG original differs')
|
||||
check(jpeg_download['headers'].get_content_type() == 'image/jpeg', 'JPEG MIME differs')
|
||||
for name in ['../x.png', 'a\\b.png', '\x00.png', '\n.png']:
|
||||
c.call('POST', base+'/attachments?filename='+quote(name, safe=''), 400, actor=a,
|
||||
raw=png, headers={'Content-Type':'image/png'})
|
||||
@@ -43,4 +56,4 @@ c.call('POST',base+'/messages',409,actor=a,body={'text':'different'},headers={'I
|
||||
# Default [] and explicit [] are equivalent.
|
||||
c.call('POST',base+'/messages',201,actor=a,body={'text':'one logical message','attachment_ids':[]},
|
||||
headers={'Idempotency-Key':key},schema='Message')
|
||||
print('PASS: invalid files, ACL, cross-chat references, concurrent idempotency')
|
||||
print('PASS: JPEG round-trip, invalid files, ACL, cross-chat references, concurrent idempotency')
|
||||
|
||||
Reference in New Issue
Block a user