@@ -38,7 +38,6 @@ async def callee(tx: ydb.aio.QueryTxContext):
3838 assert msg .data .decode () == "123"
3939
4040
41- # @pytest.mark.skip("Not implemented yet.")
4241class TestTopicTransactionalWriter :
4342 async def test_commit (self , driver : ydb .aio .Driver , topic_path , topic_reader : ydb .TopicReaderAsyncIO ):
4443 async with ydb .aio .QuerySessionPool (driver ) as pool :
@@ -65,3 +64,65 @@ async def callee(tx: ydb.aio.QueryTxContext):
6564
6665 with pytest .raises (asyncio .TimeoutError ):
6766 await wait_for (topic_reader .receive_message (), 0.1 )
67+
68+ async def test_no_msg_writter_in_error_case (
69+ self , driver : ydb .aio .Driver , topic_path , topic_reader : ydb .TopicReaderAsyncIO
70+ ):
71+ async with ydb .aio .QuerySessionPool (driver ) as pool :
72+
73+ async def callee (tx : ydb .aio .QueryTxContext ):
74+ tx_writer = driver .topic_client .tx_writer (tx , topic_path )
75+ await tx_writer .write (ydb .TopicWriterMessage (data = "123" .encode ()))
76+
77+ raise BaseException ("error" )
78+
79+ with pytest .raises (BaseException ):
80+ await pool .retry_tx_async (callee )
81+
82+ with pytest .raises (asyncio .TimeoutError ):
83+ await wait_for (topic_reader .receive_message (), 0.1 )
84+
85+
86+ class TestTopicTransactionalWriterSync :
87+ def test_commit (self , driver_sync : ydb .Driver , topic_path , topic_reader_sync : ydb .TopicReader ):
88+ with ydb .QuerySessionPool (driver_sync ) as pool :
89+
90+ def callee (tx : ydb .QueryTxContext ):
91+ tx_writer = driver_sync .topic_client .tx_writer (tx , topic_path )
92+ tx_writer .write (ydb .TopicWriterMessage (data = "123" .encode ()))
93+
94+ pool .retry_tx_sync (callee )
95+
96+ msg = topic_reader_sync .receive_message (timeout = 0.1 )
97+ assert msg .data .decode () == "123"
98+
99+ def test_rollback (self , driver_sync : ydb .aio .Driver , topic_path , topic_reader_sync : ydb .TopicReader ):
100+ with ydb .QuerySessionPool (driver_sync ) as pool :
101+
102+ def callee (tx : ydb .QueryTxContext ):
103+ tx_writer = driver_sync .topic_client .tx_writer (tx , topic_path )
104+ tx_writer .write (ydb .TopicWriterMessage (data = "123" .encode ()))
105+
106+ tx .rollback ()
107+
108+ pool .retry_tx_sync (callee )
109+
110+ with pytest .raises (TimeoutError ):
111+ topic_reader_sync .receive_message (timeout = 0.1 )
112+
113+ def test_no_msg_writter_in_error_case (
114+ self , driver_sync : ydb .Driver , topic_path , topic_reader_sync : ydb .TopicReaderAsyncIO
115+ ):
116+ with ydb .QuerySessionPool (driver_sync ) as pool :
117+
118+ def callee (tx : ydb .QueryTxContext ):
119+ tx_writer = driver_sync .topic_client .tx_writer (tx , topic_path )
120+ tx_writer .write (ydb .TopicWriterMessage (data = "123" .encode ()))
121+
122+ raise BaseException ("error" )
123+
124+ with pytest .raises (BaseException ):
125+ pool .retry_tx_sync (callee )
126+
127+ with pytest .raises (TimeoutError ):
128+ topic_reader_sync .receive_message (timeout = 0.1 )
0 commit comments