fix: неопределённый исход MarkReady не удаляет объект; 503 вместо 415 при отказе S3

This commit is contained in:
2026-11-04 20:54:28 +03:00
parent 3ffd41cf3c
commit 5119d0b5fd
3 changed files with 158 additions and 13 deletions
+13 -6
View File
@@ -137,11 +137,14 @@ def scenario_db_gap(c):
time.sleep(max(0, 45 - (time.time() - state.get('paused_at', time.time()))))
compose('unpause', 'postgres')
wait_ready(c)
time.sleep(3) # отложенный UPDATE (если был) успевает закоммититься после unpause
rows = psql("SELECT id || ' ' || status FROM attachments WHERE chat_id = '%s'" % chat['id'])
objs = mc('mc ls --recursive s3/%s/a/%s/ | wc -l' % (BUCKET, chat['id'])).stdout.strip()
status_after = rows.split()[-1] if rows else 'none'
check(st != 201, 'upload must not report success when metadata was not committed (got %s)' % st)
check(rows.endswith(' uploading'), 'expected one leftover intent, got %r' % rows)
check(objs == '0', 'compensation must delete the object, objects=' + objs)
# Главный инвариант: нет строки ready без объекта.
check(not (status_after == 'ready' and objs == '0'), 'ready row without object: %r objs=%s' % (rows, objs))
check(status_after in ('ready', 'uploading', 'none'), 'unexpected state %r' % rows)
# Reconciler (короткий grace для теста) убирает брошенное намерение.
psql("UPDATE attachments SET updated_at = now() - interval '30 minutes' WHERE chat_id = '%s'" % chat['id'])
for _ in range(10):
@@ -152,10 +155,14 @@ def scenario_db_gap(c):
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)},
'reconciler_fixed': rep['fixed'], 'rows_after_reconcile': int(after)}
final = psql("SELECT status FROM attachments WHERE chat_id = '%s'" % chat['id'])
final_objs = mc('mc ls --recursive s3/%s/a/%s/ | wc -l' % (BUCKET, chat['id'])).stdout.strip()
# После reconciler — только согласованные состояния: (ready, 1 объект) или (нет строки, 0 объектов).
check((final == 'ready' and final_objs == '1') or (final == '' and final_objs == '0'),
'inconsistent after reconcile: row=%r objects=%s' % (final, final_objs))
return {'client_status': st, 'seconds': round(time.time() - t0, 1),
'after_gap': {'row_status': status_after, 'objects': int(objs)},
'reconciler_fixed': rep['fixed'], 'after_reconcile': {'row_status': final or 'none', 'objects': int(final_objs)}}
def scenario_security(c):