File tree Expand file tree Collapse file tree
tests_integration/consumer Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import asyncio
2+ import json
23from _asyncio import Task
34
45import structlog
56from aio_pika .abc import AbstractIncomingMessage
7+ from fastapi .encoders import jsonable_encoder
8+
9+ from app .model .response .sample import Sample
610from app .rabbit_mq .rabbit_mq_client import get_connection
711from app .config import settings
812
@@ -12,10 +16,15 @@ async def process_inbound_message_task(message: AbstractIncomingMessage):
1216 async with message .process (): # Automatically ACKs if no exception occurs
1317 payload_string : str = message .body .decode ()
1418 logger .info (
15- f"Processed inbound message { payload_string } " , payload = payload_string
19+ f"Received inbound message { payload_string } " , payload = payload_string
20+ )
21+ samples = [Sample (** item ) for item in json .loads (payload_string )]
22+ logger .info (
23+ f"Processed inbound message { payload_string } " , samples = jsonable_encoder (samples )
1624 )
1725
1826
27+
1928async def start_inbound_consumer () -> Task [str ]:
2029 logger = structlog .get_logger ()
2130 # Create a dedicated channel for this consumer group
Original file line number Diff line number Diff line change 88import pytest
99import structlog
1010from assertpy import assert_that
11+ from deepdiff import DeepDiff
1112from fastapi .encoders import jsonable_encoder
1213from fastapi .testclient import TestClient
1314from tenacity import Retrying , stop_after_delay , wait_fixed
@@ -41,9 +42,9 @@ async def test_inbound_consumer_handles_message_successfully(
4142 updated_datetime = datetime .datetime .now (datetime .UTC ),
4243 version = 1 ,
4344 )
44- samples : list [Sample ] = [sample1 , sample2 ]
45+ input_samples : list [Sample ] = [sample1 , sample2 ]
4546
46- await publish_to_inbound (samples )
47+ await publish_to_inbound (input_samples )
4748
4849 for attempt in Retrying (
4950 stop = stop_after_delay (5 ), wait = wait_fixed (0.5 ), reraise = True
@@ -59,6 +60,14 @@ async def test_inbound_consumer_handles_message_successfully(
5960 )
6061 )
6162 assert_that (inbound_consumer_logs ).is_length (1 )
63+ consumed_samples : list [dict [str , Any ]] = inbound_consumer_logs [0 ]["samples" ]
64+ assert_that (
65+ DeepDiff (
66+ consumed_samples ,
67+ jsonable_encoder (input_samples ),
68+ ignore_order = True ,
69+ )
70+ ).is_empty ()
6271
6372
6473async def publish_to_inbound (samples : list [Sample ]):
You can’t perform that action at this time.
0 commit comments