Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions faststream/redis/subscriber/usecases/stream_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ async def get_one(
stream_message = await self._xreadgroup(
count=1,
block=math.ceil(timeout * 1000),
noack=self.stream_sub.no_ack,
)
if not stream_message:
return None
Expand Down Expand Up @@ -323,6 +324,7 @@ async def __aiter__(self) -> AsyncIterator["RedisStreamMessage"]:
stream_message = await self._xreadgroup(
count=1,
block=math.ceil(timeout * 1000),
noack=self.stream_sub.no_ack,
)
if not stream_message:
continue
Expand Down
37 changes: 37 additions & 0 deletions tests/brokers/redis/test_manual_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import anyio
import pytest

from faststream.redis import RedisBroker, RedisStreamMessage, StreamSub


@pytest.mark.connected()
@pytest.mark.redis()
@pytest.mark.asyncio()
@pytest.mark.parametrize("no_ack", (False, True))
@pytest.mark.parametrize("iterate", (False, True))
async def test_manual_stream_read_respects_no_ack(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s move this test to tests/brokers/redis/test_consume.py and split it into 2 tests: the 1 will be anext(aiter(sub)), the second get_one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @IvanKirpichnikov ! I've moved the tests into TestConsumeStream in test_consume.py and split them into separate get_one() and anext(aiter(sub)) tests, as suggested. Both retain coverage for no_ack=True and no_ack=False.

queue: str,
no_ack: bool,
iterate: bool,
) -> None:
broker = RedisBroker()
subscriber = broker.subscriber(
stream=StreamSub(queue, group=queue, consumer="reader", no_ack=no_ack),
)

async with broker:
await broker.start()
await broker.publish("hello", stream=queue)

message: RedisStreamMessage | None
if iterate:
with anyio.fail_after(3):
message = await anext(aiter(subscriber))
else:
message = await subscriber.get_one(timeout=3)

assert message is not None
assert await message.decode() == "hello"
client = await broker.connect()
pending = await client.xpending(queue, queue) # type: ignore[no-untyped-call]
assert pending["pending"] == (0 if no_ack else 1)
Loading