Skip to content

Commit 9925a77

Browse files
more tests
1 parent 769a65b commit 9925a77

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

src/Ydb.Sdk/src/Ado/Session/RetryableSession.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void Dispose()
4848
{
4949
}
5050

51-
private static YdbException NotSupportedTransaction => new("Transactions are not supported in retryable sessions");
51+
private static YdbException NotSupportedTransaction => new("Transactions are not supported in retryable session");
5252
}
5353

5454
internal sealed class InMemoryServerStream : IServerStream<ExecuteQueryResponsePart>
@@ -108,14 +108,10 @@ public async Task<bool> MoveNextAsync(CancellationToken cancellationToken = defa
108108
}
109109
}, cancellationToken);
110110

111-
if (_index + 1 >= _responses.Count)
112-
return false;
113-
114-
_index++;
115-
return true;
111+
return ++_index < _responses.Count;
116112
}
117113

118-
public ExecuteQueryResponsePart Current => _responses is not null && _index < _responses.Count
114+
public ExecuteQueryResponsePart Current => _responses is not null && _index >= 0 && _index < _responses.Count
119115
? _responses[_index]
120116
: throw new InvalidOperationException("Enumeration has not started or has already finished");
121117

src/Ydb.Sdk/test/Ydb.Sdk.Ado.Tests/Session/RetryableSessionTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ public async Task MoveNextAsync_SucceedsOnThirdAttempt_StopsRetrying()
9999
null
100100
);
101101

102+
Assert.Throws<InvalidOperationException>(() => inMemoryStream.Current);
102103
var hasItem = await inMemoryStream.MoveNextAsync();
103104
Assert.True(hasItem);
104105
Assert.False(inMemoryStream.Current.Status.IsNotSuccess());
106+
Assert.False(await inMemoryStream.MoveNextAsync());
107+
Assert.Throws<InvalidOperationException>(() => inMemoryStream.Current);
105108

106109
Assert.Equal(3, factory.SessionOpenedCount);
107110
}

src/Ydb.Sdk/test/Ydb.Sdk.Ado.Tests/YdbDataSourceTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,15 @@ public async Task ExecuteInTransactionAsync_WhenTLI_ThenRetriesUntilSuccess(int
246246
await new YdbCommand(ydbConnection) { CommandText = $"DROP TABLE {tableName}" }.ExecuteNonQueryAsync();
247247
}
248248
}
249+
250+
[Fact]
251+
public async Task RetryableConnection_WhenOpenTransaction_Throws()
252+
{
253+
await using var ydbConnection = await _dataSource.OpenRetryableConnectionAsync();
254+
await using var transaction = ydbConnection.BeginTransaction();
255+
256+
Assert.Equal("Transactions are not supported in retryable session",
257+
(await Assert.ThrowsAsync<YdbException>(async () => await new YdbCommand(ydbConnection)
258+
{ CommandText = "SELECT 1" }.ExecuteScalarAsync())).Message);
259+
}
249260
}

0 commit comments

Comments
 (0)