File tree Expand file tree Collapse file tree 2 files changed +33
-11
lines changed Expand file tree Collapse file tree 2 files changed +33
-11
lines changed Original file line number Diff line number Diff line change @@ -214,15 +214,16 @@ public Task<TResult> ExecuteAsync<TResult>(
214214 return await func ( ydbConnection , ct ) ;
215215 } , cancellationToken ) ;
216216
217- public Task ExecuteInTransactionAsync ( Func < YdbConnection , Task > func ,
218- TransactionMode transactionMode = TransactionMode . SerializableRw ) =>
219- _retryPolicyExecutor . ExecuteAsync ( async cancellationToken =>
220- {
221- await using var ydbConnection = await OpenConnectionAsync ( cancellationToken ) ;
222- await using var transaction = ydbConnection . BeginTransaction ( transactionMode ) ;
223- await func ( ydbConnection ) ;
224- await transaction . CommitAsync ( cancellationToken ) ;
225- } ) ;
217+ public Task ExecuteInTransactionAsync (
218+ Func < YdbConnection , Task > func ,
219+ TransactionMode transactionMode = TransactionMode . SerializableRw
220+ ) => _retryPolicyExecutor . ExecuteAsync ( async cancellationToken =>
221+ {
222+ await using var ydbConnection = await OpenConnectionAsync ( cancellationToken ) ;
223+ await using var transaction = ydbConnection . BeginTransaction ( transactionMode ) ;
224+ await func ( ydbConnection ) ;
225+ await transaction . CommitAsync ( cancellationToken ) ;
226+ } ) ;
226227
227228 public Task < TResult > ExecuteInTransactionAsync < TResult > (
228229 Func < YdbConnection , Task < TResult > > func ,
Original file line number Diff line number Diff line change 11using Xunit ;
22using Ydb . Sdk . Ado . RetryPolicy ;
3- using Ydb . Sdk . Ado . Tests . Session ;
43
54namespace Ydb . Sdk . Ado . Tests ;
65
@@ -92,7 +91,7 @@ await _dataSource.ExecuteAsync(_ =>
9291 }
9392
9493 return Task . CompletedTask ;
95- } ) ;
94+ } , new YdbRetryPolicyConfig { EnableRetryIdempotence = true } ) ;
9695 }
9796
9897 [ Theory ]
@@ -180,4 +179,26 @@ await _dataSource.ExecuteAsync(ydbConnection =>
180179 Assert . Equal ( 3 , ydbConnections . Count ) ;
181180 Assert . True ( ydbConnections . Distinct ( ) . Count ( ) == ydbConnections . Count ) ; // new one every time
182181 }
182+
183+ [ Fact ]
184+ public async Task ExecuteAsync_CancelsBetweenRetries ( )
185+ {
186+ using var cts = new CancellationTokenSource ( ) ;
187+ var attempt = 0 ;
188+
189+ await Assert . ThrowsAnyAsync < OperationCanceledException > ( async ( ) =>
190+ {
191+ await _dataSource . ExecuteAsync ( async ( _ , _ ) =>
192+ {
193+ attempt ++ ;
194+ if ( attempt == 1 )
195+ {
196+ await cts . CancelAsync ( ) ;
197+ throw new YdbException ( StatusCode . BadSession , "Bad" ) ;
198+ }
199+ } , cts . Token ) ;
200+ } ) ;
201+
202+ Assert . Equal ( 1 , attempt ) ;
203+ }
183204}
You can’t perform that action at this time.
0 commit comments