fix: an unavailable Tiny (5xx) retries the whole delivery instead of sending the order without its seller
The seller cannot be set after the order is made (order 151250), so a server error while reading the contact now waits for the outbox's next try, as a 429 already did. A reading Tiny refuses for good still lets the order go, and now reaches Sentry instead of a warning no one sees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -77,7 +77,7 @@ class FakeTinyCase(unittest.TestCase):
|
||||
if request.method == 'GET' and path.startswith('/contatos/'):
|
||||
wanted = int(path.rsplit('/', 1)[-1])
|
||||
if self.refuse_contact:
|
||||
return httpx.Response(429 if self.refuse_contact == 429 else 503, text='indisponível')
|
||||
return httpx.Response(self.refuse_contact, text='indisponível')
|
||||
return httpx.Response(200, json=next(c for c in self.contacts if c['id'] == wanted))
|
||||
if request.method == 'POST' and path == '/contatos':
|
||||
contact = {**json.loads(request.content), 'id': 500 + len(self.contacts)}
|
||||
@@ -267,11 +267,26 @@ class TinyTests(FakeTinyCase):
|
||||
self.tiny.deliver('k2', {**PAID, 'number': 43})
|
||||
self.assertNotIn('vendedor', self.orders[1])
|
||||
|
||||
def test_a_failed_seller_reading_does_not_hold_the_order(self):
|
||||
def test_a_refused_seller_reading_does_not_hold_the_order_and_reaches_sentry(self):
|
||||
self.contacts.append({'id': 321, 'cpfCnpj': '11.222.333/0001-81', 'vendedor': {'id': 977231477}})
|
||||
self.refuse_contact = True
|
||||
self.assertEqual(self.tiny.deliver('k1', PAID)['status'], 'created')
|
||||
self.refuse_contact = 400
|
||||
with self.assertLogs(level='ERROR') as logged:
|
||||
self.assertEqual(self.tiny.deliver('k1', PAID)['status'], 'created')
|
||||
self.assertNotIn('vendedor', self.orders[0])
|
||||
self.assertIn('without one', logged.output[0])
|
||||
|
||||
def test_an_unavailable_tiny_retries_the_delivery_instead_of_dropping_the_seller(self):
|
||||
# The seller cannot be set after the order is made (order 151250): a
|
||||
# 5xx while reading it tries the whole delivery again.
|
||||
from app.tiny import TinyUnavailable
|
||||
self.contacts.append({'id': 321, 'cpfCnpj': '11.222.333/0001-81', 'vendedor': {'id': 977231477}})
|
||||
self.refuse_contact = 503
|
||||
with self.assertRaises(TinyUnavailable):
|
||||
self.tiny.deliver('k1', PAID)
|
||||
self.assertEqual(self.orders, [])
|
||||
self.refuse_contact = None
|
||||
self.tiny.deliver('k1', PAID)
|
||||
self.assertEqual(self.orders[0]['vendedor'], {'id': 977231477})
|
||||
|
||||
def test_a_busy_tiny_retries_the_delivery_instead_of_dropping_the_seller(self):
|
||||
from app.tiny import TinyRateLimit
|
||||
|
||||
Reference in New Issue
Block a user