Skip to content

Commit e216d4a

Browse files
committed
Handle ack_sync and test methods as async
1 parent de873fc commit e216d4a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

faststream/nats/message.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ async def ack(self) -> None:
1717
await self.raw_message.ack()
1818
await super().ack()
1919

20-
def ack_sync(self) -> None:
20+
async def ack_sync(self) -> None:
2121
if not self.raw_message._ackd:
22-
self.raw_message.ack_sync()
23-
super().ack()
22+
await self.raw_message.ack_sync()
23+
await super().ack()
2424

2525
async def nack(
2626
self,

tests/brokers/nats/test_consume.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from unittest.mock import MagicMock, Mock, patch
2+
from unittest.mock import Mock, patch
33

44
import pytest
55
from nats.aio.msg import Msg
@@ -224,21 +224,21 @@ async def test_consume_ack_sync_manual(
224224

225225
@consume_broker.subscriber(queue, stream=stream)
226226
async def handler(msg: NatsMessage):
227-
msg.ack_sync()
227+
await msg.ack_sync()
228228
event.set()
229229

230230
async with self.patch_broker(consume_broker) as br:
231231
await br.start()
232232

233-
with patch.object(Msg, "ack_sync", new_callable=MagicMock) as m:
233+
with patch.object(Msg, "ack_sync", spy_decorator(Msg.ack_sync)) as m:
234234
await asyncio.wait(
235235
(
236236
asyncio.create_task(br.publish("hello", queue)),
237237
asyncio.create_task(event.wait()),
238238
),
239239
timeout=3,
240240
)
241-
m.assert_called_once()
241+
m.mock.assert_called_once()
242242

243243
assert event.is_set()
244244

0 commit comments

Comments
 (0)