55
66@pytest .mark .asyncio
77class TestTopicReaderAsyncIO :
8- async def test_read_batch (self , driver , topic_path , topic_with_messages , topic_consumer ):
9- reader = driver .topic_client .reader (topic_path , topic_consumer )
8+ async def test_read_batch (self , driver , topic_with_messages , topic_consumer ):
9+ reader = driver .topic_client .reader (topic_with_messages , topic_consumer )
1010 batch = await reader .receive_batch ()
1111
1212 assert batch is not None
@@ -18,30 +18,30 @@ async def test_link_to_client(self, driver, topic_path, topic_consumer):
1818 reader = driver .topic_client .reader (topic_path , topic_consumer )
1919 assert reader ._parent is driver .topic_client
2020
21- async def test_read_message (self , driver , topic_path , topic_with_messages , topic_consumer ):
22- reader = driver .topic_client .reader (topic_path , topic_consumer )
21+ async def test_read_message (self , driver , topic_with_messages , topic_consumer ):
22+ reader = driver .topic_client .reader (topic_with_messages , topic_consumer )
2323 msg = await reader .receive_message ()
2424
2525 assert msg is not None
2626 assert msg .seqno
2727
2828 await reader .close ()
2929
30- async def test_read_and_commit_with_close_reader (self , driver , topic_path , topic_with_messages , topic_consumer ):
31- async with driver .topic_client .reader (topic_path , topic_consumer ) as reader :
30+ async def test_read_and_commit_with_close_reader (self , driver , topic_with_messages , topic_consumer ):
31+ async with driver .topic_client .reader (topic_with_messages , topic_consumer ) as reader :
3232 message = await reader .receive_message ()
3333 reader .commit (message )
3434
35- async with driver .topic_client .reader (topic_path , topic_consumer ) as reader :
35+ async with driver .topic_client .reader (topic_with_messages , topic_consumer ) as reader :
3636 message2 = await reader .receive_message ()
3737 assert message != message2
3838
39- async def test_read_and_commit_with_ack (self , driver , topic_path , topic_with_messages , topic_consumer ):
40- reader = driver .topic_client .reader (topic_path , topic_consumer )
39+ async def test_read_and_commit_with_ack (self , driver , topic_with_messages , topic_consumer ):
40+ reader = driver .topic_client .reader (topic_with_messages , topic_consumer )
4141 batch = await reader .receive_batch ()
4242 await reader .commit_with_ack (batch )
4343
44- reader = driver .topic_client .reader (topic_path , topic_consumer )
44+ reader = driver .topic_client .reader (topic_with_messages , topic_consumer )
4545 batch2 = await reader .receive_batch ()
4646 assert batch .messages [0 ] != batch2 .messages [0 ]
4747
@@ -71,10 +71,35 @@ def decode(b: bytes):
7171 batch = await reader .receive_batch ()
7272 assert batch .messages [0 ].data .decode () == "123"
7373
74+ async def test_read_from_two_topics (self , driver , topic_path , topic2_path , topic_consumer ):
75+ async with driver .topic_client .writer (topic_path ) as writer :
76+ await writer .write ("1" )
77+ await writer .flush ()
78+
79+ async with driver .topic_client .writer (topic2_path ) as writer :
80+ await writer .write ("2" )
81+ await writer .flush ()
82+
83+ messages = []
84+ async with driver .topic_client .reader (
85+ [
86+ topic_path ,
87+ ydb .TopicReaderSelector (path = topic2_path ),
88+ ],
89+ consumer = topic_consumer ,
90+ ) as reader :
91+ for _ in range (2 ):
92+ message = await reader .receive_message ()
93+ messages .append (message )
94+
95+ messages = [message .data .decode () for message in messages ]
96+ messages .sort ()
97+ assert messages == ["1" , "2" ]
98+
7499
75100class TestTopicReaderSync :
76- def test_read_batch (self , driver_sync , topic_path , topic_with_messages , topic_consumer ):
77- reader = driver_sync .topic_client .reader (topic_path , topic_consumer )
101+ def test_read_batch (self , driver_sync , topic_with_messages , topic_consumer ):
102+ reader = driver_sync .topic_client .reader (topic_with_messages , topic_consumer )
78103 batch = reader .receive_batch ()
79104
80105 assert batch is not None
@@ -86,30 +111,30 @@ def test_link_to_client(self, driver_sync, topic_path, topic_consumer):
86111 reader = driver_sync .topic_client .reader (topic_path , topic_consumer )
87112 assert reader ._parent is driver_sync .topic_client
88113
89- def test_read_message (self , driver_sync , topic_path , topic_with_messages , topic_consumer ):
90- reader = driver_sync .topic_client .reader (topic_path , topic_consumer )
114+ def test_read_message (self , driver_sync , topic_with_messages , topic_consumer ):
115+ reader = driver_sync .topic_client .reader (topic_with_messages , topic_consumer )
91116 msg = reader .receive_message ()
92117
93118 assert msg is not None
94119 assert msg .seqno
95120
96121 reader .close ()
97122
98- def test_read_and_commit_with_close_reader (self , driver_sync , topic_path , topic_with_messages , topic_consumer ):
99- with driver_sync .topic_client .reader (topic_path , topic_consumer ) as reader :
123+ def test_read_and_commit_with_close_reader (self , driver_sync , topic_with_messages , topic_consumer ):
124+ with driver_sync .topic_client .reader (topic_with_messages , topic_consumer ) as reader :
100125 message = reader .receive_message ()
101126 reader .commit (message )
102127
103- with driver_sync .topic_client .reader (topic_path , topic_consumer ) as reader :
128+ with driver_sync .topic_client .reader (topic_with_messages , topic_consumer ) as reader :
104129 message2 = reader .receive_message ()
105130 assert message != message2
106131
107- def test_read_and_commit_with_ack (self , driver_sync , topic_path , topic_with_messages , topic_consumer ):
108- reader = driver_sync .topic_client .reader (topic_path , topic_consumer )
132+ def test_read_and_commit_with_ack (self , driver_sync , topic_with_messages , topic_consumer ):
133+ reader = driver_sync .topic_client .reader (topic_with_messages , topic_consumer )
109134 batch = reader .receive_batch ()
110135 reader .commit_with_ack (batch )
111136
112- reader = driver_sync .topic_client .reader (topic_path , topic_consumer )
137+ reader = driver_sync .topic_client .reader (topic_with_messages , topic_consumer )
113138 batch2 = reader .receive_batch ()
114139 assert batch .messages [0 ] != batch2 .messages [0 ]
115140
0 commit comments