fix: 96 DPI is accepted as the Site shows it; big carts upload 4 at a time (Sentry 12/11)
The server compared the raw lowest resolution (95,6) with 96 but printed it rounded, refusing '96 DPI abaixo do mínimo de 96'; it now decides on the same rounded value the Site shows. A big cart started every upload at once and hit the limit of 10 pending uploads (429): the limit is 30, that refusal carries Retry-After so the Site retries by itself, and the Site runs at most 4 uploads at a time. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -142,6 +142,20 @@ class GradeCheckTests(unittest.TestCase):
|
||||
for dpi in (200, 287, 293):
|
||||
self.assertIsNone(issue(dpi), dpi)
|
||||
self.assertEqual(grade_check.grade_of(dpi), 100)
|
||||
# The Site shows the rounded DPI: 95.6 is 96 and passes; 95.4 is 95
|
||||
# and is refused. The warning band starts at the shown 199.
|
||||
width_px = lambda dpi: round(dpi * 57 / 2.54)
|
||||
for dpi in (95.6, 95.4, 199.6, 199.4):
|
||||
files.blobs[f'{dpi}.png'] = encoded('PNG', (width_px(dpi), 20))
|
||||
rows[f'{dpi}.png'] = {'name': f'{dpi}.png', 'size': 1}
|
||||
# 95.6 is shown as 96: the warning band, not the refusal; acknowledged,
|
||||
# it goes through. 95.4 is shown as 95 and refused.
|
||||
self.assertNotIn('abaixo do mínimo', issue(95.6))
|
||||
self.assertIn('confirme a ressalva', issue(95.6))
|
||||
self.assertIsNone(issue(95.6, 'warning', True))
|
||||
self.assertIn('95 DPI', issue(95.4))
|
||||
self.assertIsNone(issue(199.6))
|
||||
self.assertIn('confirme a ressalva', issue(199.4))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -4,8 +4,12 @@ takes up to 200 files per item (Sentry DTF-WEB-1).
|
||||
|
||||
Run against the local stack: python -m tests.upload_limits_test
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
from urllib.error import HTTPError
|
||||
from urllib.request import Request
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from fastapi import HTTPException
|
||||
@@ -13,7 +17,7 @@ from fastapi import HTTPException
|
||||
from app.api.uploads import UPLOAD_START_IP_LIMIT, UPLOAD_START_LIMIT
|
||||
from app.core import db
|
||||
from app.core.auth import rate_limit
|
||||
from tests.smoke_test import Client, upload_bytes
|
||||
from tests.smoke_test import BASE, Client, upload_bytes, with_host
|
||||
|
||||
PNG = (Path(__file__).resolve().parent / 'fixtures' / 'final-300.png').read_bytes()
|
||||
TOO_MANY = 'Este item tem mais de 200 arquivos. Divida em dois itens.'
|
||||
@@ -59,6 +63,25 @@ def run():
|
||||
else:
|
||||
raise AssertionError('the per-source upload bucket accepted above its limit')
|
||||
|
||||
# DTF-WEB-3: a burst above MAX_PENDING_UPLOADS (now 30). The 31st start
|
||||
# answers 429 with Retry-After 15, so the Site waits and retries alone.
|
||||
assert int(os.environ.get('MAX_PENDING_UPLOADS', '30')) == 30
|
||||
pending = []
|
||||
for index in range(30):
|
||||
pending.append(client.call('/uploads', {'name': f'PENDING-{index}.png', 'size': 1})['id'])
|
||||
burst = Request(BASE + '/api/uploads',
|
||||
data=json.dumps({'name': 'PENDING-31.png', 'size': 1}).encode(),
|
||||
headers=with_host({'Content-Type': 'application/json'}), method='POST')
|
||||
try:
|
||||
with client.opener.open(burst, timeout=30) as response:
|
||||
raise AssertionError('the pending-upload cap accepted the 31st upload')
|
||||
except HTTPError as error:
|
||||
assert error.code == 429, error
|
||||
assert error.headers.get('Retry-After') == '15', error.headers
|
||||
assert json.load(error)['detail'] == 'Muitos envios ao mesmo tempo. O site tenta de novo sozinho.'
|
||||
for uid in pending:
|
||||
client.call(f'/uploads/{uid}', expected=200, method='DELETE')
|
||||
|
||||
# Sentry DTF-WEB-1: 66 sheets in one ready-sheet item is quoted and
|
||||
# approved; the old cap of 20 refused it with a generic 422.
|
||||
uploads = [upload_bytes(client, PNG, name=f'SHEET66-{index}.png') for index in range(66)]
|
||||
|
||||
Reference in New Issue
Block a user