9
9
from taskiq_aio_pika .broker import AioPikaBroker
10
10
11
11
12
- async def get_first_task (broker : AioPikaBroker ) -> BrokerMessage : # type: ignore
12
+ async def get_first_task (broker : AioPikaBroker ) -> bytes : # type: ignore
13
13
"""
14
14
Get first message from the queue.
15
15
@@ -36,7 +36,7 @@ async def test_kick_success(broker: AioPikaBroker) -> None:
36
36
sent = BrokerMessage (
37
37
task_id = task_id ,
38
38
task_name = task_name ,
39
- message = "my_msg" ,
39
+ message = b "my_msg" ,
40
40
labels = {
41
41
"label1" : "val1" ,
42
42
},
@@ -46,7 +46,7 @@ async def test_kick_success(broker: AioPikaBroker) -> None:
46
46
47
47
message = await asyncio .wait_for (get_first_task (broker ), timeout = 0.4 )
48
48
49
- assert message == sent
49
+ assert message == sent . message
50
50
51
51
52
52
@pytest .mark .anyio
@@ -111,10 +111,7 @@ async def test_listen(
111
111
112
112
message = await asyncio .wait_for (get_first_task (broker ), timeout = 0.4 )
113
113
114
- assert message .message == "test_message"
115
- assert message .labels == {"label1" : "label_val" }
116
- assert message .task_id == "test_id"
117
- assert message .task_name == "task_name"
114
+ assert message == b"test_message"
118
115
119
116
120
117
@pytest .mark .anyio
@@ -124,7 +121,7 @@ async def test_wrong_format(
124
121
test_channel : Channel ,
125
122
) -> None :
126
123
"""
127
- Tests that messages with wrong format are ignored .
124
+ Tests that messages with wrong format are still received .
128
125
129
126
:param broker: aio-pika broker.
130
127
:param queue_name: test queue name.
@@ -136,8 +133,9 @@ async def test_wrong_format(
136
133
routing_key = queue_name ,
137
134
)
138
135
139
- with pytest .raises (asyncio .TimeoutError ):
140
- await asyncio .wait_for (get_first_task (broker ), 0.4 )
136
+ msg_bytes = await asyncio .wait_for (get_first_task (broker ), 0.4 )
137
+
138
+ assert msg_bytes == b"wrong"
141
139
142
140
with pytest .raises (QueueEmpty ):
143
141
await queue .get ()
@@ -168,7 +166,7 @@ async def test_delayed_message(
168
166
broker_msg = BrokerMessage (
169
167
task_id = "1" ,
170
168
task_name = "name" ,
171
- message = "message" ,
169
+ message = b "message" ,
172
170
labels = {"delay" : "2" },
173
171
)
174
172
await broker .kick (broker_msg )
0 commit comments