|
| 1 | +import asyncio |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
3 | 5 | import ydb |
@@ -161,3 +163,44 @@ def decode(b: bytes): |
161 | 163 | with driver_sync.topic_client.reader(topic_path, topic_consumer, decoders={codec: decode}) as reader: |
162 | 164 | batch = reader.receive_batch() |
163 | 165 | assert batch.messages[0].data.decode() == "123" |
| 166 | + |
| 167 | + |
| 168 | +@pytest.mark.asyncio |
| 169 | +class TestBugFixesAsync: |
| 170 | + @pytest.mark.skip("LOGBROKER-8319") |
| 171 | + async def test_issue_297_bad_handle_stop_partition(self, driver, topic_consumer, topic_with_two_partitions_path: str): |
| 172 | + |
| 173 | + async def wait(fut): |
| 174 | + return await asyncio.wait_for(fut, timeout=10) |
| 175 | + |
| 176 | + topic = topic_with_two_partitions_path # type: str |
| 177 | + |
| 178 | + async with driver.topic_client.writer(topic, partition_id=0) as writer: |
| 179 | + await writer.write_with_ack("01") |
| 180 | + |
| 181 | + async with driver.topic_client.writer(topic, partition_id=1) as writer: |
| 182 | + await writer.write_with_ack("1") |
| 183 | + |
| 184 | + # Start first reader and receive messages from both partitions |
| 185 | + reader0 = driver.topic_client.reader(topic, consumer=topic_consumer) |
| 186 | + await wait(reader0.receive_message()) |
| 187 | + await wait(reader0.receive_message()) |
| 188 | + |
| 189 | + # Start second reader for same topic, same consumer, partition 1 |
| 190 | + reader1 = driver.topic_client.reader(ydb.TopicReaderSelector( |
| 191 | + path=topic, |
| 192 | + partitions=1, |
| 193 | + ), consumer=topic_consumer) |
| 194 | + |
| 195 | + await asyncio.sleep(0.1) |
| 196 | + |
| 197 | + # receive uncommited message from partition 1 |
| 198 | + msg = await wait(reader1.receive_message()) |
| 199 | + assert msg.data.decode() == "1" |
| 200 | + |
| 201 | + # write message to partition 0 - for reader 0 |
| 202 | + # async with driver.topic_client.writer(topic, partition_id=0) as writer: |
| 203 | + # await writer.write_with_ack("02") |
| 204 | + |
| 205 | + msg = await wait(reader0.receive_message()) |
| 206 | + assert msg.data.decode() == "02" |
0 commit comments