Skip to content

Commit 0d8fe80

Browse files
Retries and succeed scenario
1 parent ec70184 commit 0d8fe80

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

app/consumer/retry_consumer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ async def process_retry_message_task(message: AbstractIncomingMessage):
3434
headers=headers,
3535
payload_string=payload_string,
3636
)
37-
elif count <= settings.app_rabbit_inbound_max_retry and next_retry > datetime.now(
38-
UTC
37+
elif (
38+
count <= settings.app_rabbit_inbound_max_retry
39+
and next_retry > datetime.now(UTC)
3940
):
4041
await publish_to_inbound_retry(
4142
payload_string=payload_string, headers=headers

tests_integration/producer/test_inbound_producer.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from app.config import Settings
1919
from app.model.response.sample import Sample
20-
from app.producer.outbound_producer import publish_to_outbound
2120
from tests_integration.support.model.inbound_message import InboundMessage
2221

2322
PUBLISH_INBOUND_ENDPOINT = "/context/test-support/publish-inbound-messages"
@@ -110,16 +109,11 @@ def test_publish_inbound_message_publishes_to_retries_and_succeeds_on_last_attem
110109
test_client: TestClient,
111110
captured_logs: list[MutableMapping[str, Any]],
112111
):
113-
def side_effect_logic(*args, **kwargs):
114-
if mock_publish_to_outbound.call_count == 1:
115-
raise ValueError("First failure")
116-
if mock_publish_to_outbound.call_count == 2:
117-
raise TypeError("Second failure")
118-
119-
# Call 3 and all future calls fall back to the real thing
120-
return publish_to_outbound(*args, **kwargs)
121-
122-
mock_publish_to_outbound.side_effect = side_effect_logic
112+
mock_publish_to_outbound.side_effect = [
113+
ValueError("First failure"),
114+
ValueError("Second failure"),
115+
None,
116+
]
123117

124118
sample1: Sample = Sample(
125119
id=uuid.uuid4(),
@@ -182,6 +176,16 @@ def side_effect_logic(*args, **kwargs):
182176
)
183177
).is_empty()
184178

179+
for attempt in Retrying(
180+
stop=stop_after_delay(5), wait=wait_fixed(0.5), reraise=True
181+
):
182+
with attempt:
183+
assert_that(mock_publish_to_outbound.call_count).is_equal_to(3)
184+
185+
assert_that(
186+
mock_publish_to_outbound.call_args_list[2].kwargs["samples"]
187+
).is_equal_to(samples)
188+
185189

186190
def test_publish_bulk_inbound_message(
187191
enable_test_components: Settings,

0 commit comments

Comments
 (0)