@@ -95,7 +95,7 @@ public async Task ClosedYdbDataReader_WhenConnectionIsClosed_ThrowException()
9595
9696 var ydbCommand = ydbConnection . CreateCommand ( ) ;
9797 ydbCommand . CommandText = "SELECT 1; SELECT 2; SELECT 3;" ;
98- var reader = await ydbCommand . ExecuteReaderAsync ( ) ;
98+ await using var reader = await ydbCommand . ExecuteReaderAsync ( ) ;
9999 await reader . ReadAsync ( ) ;
100100
101101 Assert . Equal ( 1 , reader . GetInt32 ( 0 ) ) ;
@@ -171,7 +171,7 @@ INSERT INTO {tableName}
171171
172172 await ydbCommand . ExecuteNonQueryAsync ( ) ;
173173 ydbCommand . CommandText = $ "SELECT NULL, t.* FROM { tableName } t";
174- var ydbDataReader = await ydbCommand . ExecuteReaderAsync ( ) ;
174+ await using var ydbDataReader = await ydbCommand . ExecuteReaderAsync ( ) ;
175175 Assert . True ( await ydbDataReader . ReadAsync ( ) ) ;
176176 for ( var i = 0 ; i < 21 ; i ++ )
177177 {
@@ -209,33 +209,36 @@ public async Task YdbDataReader_WhenCancelTokenIsCanceled_ThrowYdbException()
209209 {
210210 await using var connection = await CreateOpenConnectionAsync ( ) ;
211211 var command = new YdbCommand ( connection ) { CommandText = "SELECT 1; SELECT 1; SELECT 1;" } ;
212- var ydbDataReader = await command . ExecuteReaderAsync ( ) ;
213212 using var cts = new CancellationTokenSource ( ) ;
214213 cts . Cancel ( ) ;
215214
216- await ydbDataReader . ReadAsync ( cts . Token ) ; // first part in memory
217- Assert . False ( ydbDataReader . IsClosed ) ;
218- Assert . Equal ( 1 , ydbDataReader . GetValue ( 0 ) ) ;
219- Assert . Equal ( ConnectionState . Open , connection . State ) ;
220- Assert . Equal ( StatusCode . ClientTransportTimeout ,
221- ( await Assert . ThrowsAsync < YdbException > ( async ( ) => await ydbDataReader . NextResultAsync ( cts . Token ) ) ) . Code ) ;
222- Assert . True ( ydbDataReader . IsClosed ) ;
215+ await using ( var ydbDataReader = await command . ExecuteReaderAsync ( ) )
216+ {
217+ await ydbDataReader . ReadAsync ( cts . Token ) ;
218+ Assert . False ( ydbDataReader . IsClosed ) ;
219+ Assert . Equal ( 1 , ydbDataReader . GetValue ( 0 ) ) ;
220+ Assert . Equal ( ConnectionState . Open , connection . State ) ;
221+ Assert . Equal ( StatusCode . ClientTransportTimeout ,
222+ ( await Assert . ThrowsAsync < YdbException > ( async ( ) => await ydbDataReader . NextResultAsync ( cts . Token ) ) ) . Code ) ;
223+ Assert . True ( ydbDataReader . IsClosed ) ;
224+ }
223225 Assert . Equal ( ConnectionState . Broken , connection . State ) ;
224- // ReSharper disable once MethodSupportsCancellation
225226 await connection . OpenAsync ( ) ;
226227
227228 // ReSharper disable once MethodSupportsCancellation
228- ydbDataReader = await command . ExecuteReaderAsync ( ) ;
229- // ReSharper disable once MethodSupportsCancellation
230- await ydbDataReader . NextResultAsync ( ) ;
231- await ydbDataReader . ReadAsync ( cts . Token ) ;
232- Assert . False ( ydbDataReader . IsClosed ) ;
233- Assert . Equal ( 1 , ydbDataReader . GetValue ( 0 ) ) ;
234- Assert . False ( ydbDataReader . IsClosed ) ;
235-
236- Assert . Equal ( StatusCode . ClientTransportTimeout ,
237- ( await Assert . ThrowsAsync < YdbException > ( async ( ) => await ydbDataReader . NextResultAsync ( cts . Token ) ) ) . Code ) ;
238- Assert . True ( ydbDataReader . IsClosed ) ;
229+ await using ( var ydbDataReader = await command . ExecuteReaderAsync ( ) )
230+ {
231+ // ReSharper disable once MethodSupportsCancellation
232+ await ydbDataReader . NextResultAsync ( ) ;
233+ await ydbDataReader . ReadAsync ( cts . Token ) ;
234+ Assert . False ( ydbDataReader . IsClosed ) ;
235+ Assert . Equal ( 1 , ydbDataReader . GetValue ( 0 ) ) ;
236+ Assert . False ( ydbDataReader . IsClosed ) ;
237+
238+ Assert . Equal ( StatusCode . ClientTransportTimeout ,
239+ ( await Assert . ThrowsAsync < YdbException > ( async ( ) => await ydbDataReader . NextResultAsync ( cts . Token ) ) ) . Code ) ;
240+ Assert . True ( ydbDataReader . IsClosed ) ;
241+ }
239242 Assert . Equal ( ConnectionState . Broken , connection . State ) ;
240243 }
241244
@@ -266,7 +269,7 @@ public async Task ExecuteReaderAsync_WhenExecutedYdbDataReaderThenCancelTokenIsC
266269 await using var connection = await CreateOpenConnectionAsync ( ) ;
267270 var ydbCommand = new YdbCommand ( connection ) { CommandText = "SELECT 1; SELECT 1; " } ;
268271 var cts = new CancellationTokenSource ( ) ;
269- var ydbDataReader = await ydbCommand . ExecuteReaderAsync ( cts . Token ) ;
272+ await using var ydbDataReader = await ydbCommand . ExecuteReaderAsync ( cts . Token ) ;
270273
271274 await ydbDataReader . ReadAsync ( cts . Token ) ;
272275 Assert . Equal ( 1 , ydbDataReader . GetValue ( 0 ) ) ;
@@ -501,7 +504,6 @@ PRIMARY KEY (Id)
501504
502505 var importer = conn . BeginBulkUpsertImport ( table , [ "Id" , "Name" ] ) ;
503506
504- // $rows: List<Struct<Id:Int64, Name:Text>>
505507 var rows = YdbList
506508 . Struct ( "Id" , "Name" )
507509 . AddRow ( 1L , "A" )
0 commit comments