Skip to content

Commit 68b82e1

Browse files
fix tests
1 parent 8cd524f commit 68b82e1

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

src/Ydb.Sdk/src/Services/Query/QueryClient.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class QueryClientConfig
99
public int MaxSessionPool
1010
{
1111
get => _masSessionPool;
12-
set
12+
init
1313
{
1414
if (value <= 0)
1515
{
@@ -20,18 +20,40 @@ public int MaxSessionPool
2020
}
2121
}
2222

23-
private int _masSessionPool = SessionPoolDefaultSettings.MaxSessionPool;
23+
private readonly int _masSessionPool = SessionPoolDefaultSettings.MaxSessionPool;
24+
25+
public int CreateSessionTimeout
26+
{
27+
get => _createSessionTimeout;
28+
init
29+
{
30+
if (value < 0)
31+
{
32+
throw new ArgumentOutOfRangeException(nameof(value), value,
33+
"Invalid create session timeout: " + value);
34+
}
35+
36+
_createSessionTimeout = value;
37+
}
38+
}
39+
40+
private readonly int _createSessionTimeout = SessionPoolDefaultSettings.CreateSessionTimeoutSeconds;
2441
}
2542

2643
public class QueryClient : IAsyncDisposable
2744
{
2845
private readonly SessionPool _sessionPool;
2946

30-
public QueryClient(Driver driver, QueryClientConfig? config = null)
47+
public QueryClient(IDriver driver, QueryClientConfig? config = null)
3148
{
3249
config ??= new QueryClientConfig();
3350

34-
_sessionPool = new SessionPool(driver, new SessionPoolConfig(MaxSessionPool: config.MaxSessionPool));
51+
_sessionPool = new SessionPool(driver,
52+
new SessionPoolConfig(
53+
CreateSessionTimeout: config.CreateSessionTimeout,
54+
MaxSessionPool: config.MaxSessionPool
55+
)
56+
);
3557
}
3658

3759
public Task<T> Stream<T>(string query, Func<ExecuteQueryStream, Task<T>> onStream,

src/Ydb.Sdk/tests/Ado/YdbConnectionStringBuilderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void InitConnectionStringBuilder_WhenExpectedKeys_ReturnUpdatedConnection
4343
var connectionString = new YdbConnectionStringBuilder(
4444
"Host=server;Port=2135;Database=/my/path;User=Kirill;UseTls=true;" +
4545
"ConnectTimeout=30;KeepAlivePingDelay=30;KeepAlivePingTimeout=60;" +
46-
"EnableMultipleHttp2Connections=true;CreateTimeoutSession=30;" +
46+
"EnableMultipleHttp2Connections=true;CreateSessionTimeout=30;" +
4747
"MaxSendMessageSize=1000000;MaxReceiveMessageSize=1000000;" +
4848
"DisableDiscovery=true"
4949
);
@@ -62,7 +62,7 @@ public void InitConnectionStringBuilder_WhenExpectedKeys_ReturnUpdatedConnection
6262
Assert.Equal(1000000, connectionString.MaxReceiveMessageSize);
6363
Assert.Equal("Host=server;Port=2135;Database=/my/path;User=Kirill;UseTls=True;" +
6464
"ConnectTimeout=30;KeepAlivePingDelay=30;KeepAlivePingTimeout=60;" +
65-
"EnableMultipleHttp2Connections=True;CreateTimeoutSession=30;" +
65+
"EnableMultipleHttp2Connections=True;CreateSessionTimeout=30;" +
6666
"MaxSendMessageSize=1000000;MaxReceiveMessageSize=1000000;" +
6767
"DisableDiscovery=True", connectionString.ConnectionString);
6868
Assert.True(connectionString.DisableDiscovery);

src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Ydb.Sdk.Tests.Pool;
1010
[Trait("Category", "Unit")]
1111
public class SessionPoolTests
1212
{
13-
private const int TestSessionPoolSize = 50;
13+
internal const int TestSessionPoolSize = 50;
1414

1515
private readonly TestSessionPool _testSessionPool = new();
1616

@@ -82,7 +82,8 @@ internal class TestSessionPool : SessionPool<TestSession>
8282

8383
public Status CreatedStatus { get; set; } = Status.Success;
8484

85-
public TestSessionPool() : base(NullLogger<TestSessionPool>.Instance, new SessionPoolConfig())
85+
public TestSessionPool() : base(NullLogger<TestSessionPool>.Instance,
86+
new SessionPoolConfig(MaxSessionPool: SessionPoolTests.TestSessionPoolSize, CreateSessionTimeout: 0))
8687
{
8788
}
8889

src/Ydb.Sdk/tests/Query/QueryIntegrationTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ namespace Ydb.Sdk.Tests.Query;
77

88
[Collection("Integration QueryService test")]
99
[Trait("Category", "Integration")]
10-
public class QueryIntegrationTests : IClassFixture<QueryClientFixture>, IAsyncLifetime
10+
public class QueryIntegrationTests : IClassFixture<QueryClientFixture>, IClassFixture<DriverFixture>, IAsyncLifetime
1111
{
1212
private static readonly TemporaryTables<QueryIntegrationTests> Tables = new();
1313

1414
private readonly QueryClient _queryClient;
15+
private readonly IDriver _driver;
1516

16-
public QueryIntegrationTests(QueryClientFixture queryClientFixture)
17+
public QueryIntegrationTests(QueryClientFixture queryClientFixture, DriverFixture driverFixture)
1718
{
1819
_queryClient = queryClientFixture.QueryClient;
20+
_driver = driverFixture.Driver;
1921
}
2022

2123
[Fact]
@@ -216,12 +218,13 @@ await tx.Exec($"DELETE FROM {Tables.Episodes} WHERE series_id = 2 AND season_id
216218
[Fact]
217219
public async Task Stream_ReadingMore1000RowsFromChannel_ReturnChannelExecuteParts()
218220
{
221+
await using var queryService = new QueryClient(_driver, new QueryClientConfig { CreateSessionTimeout = 0 });
219222
const int sizeSeasons = 10_000;
220223
var tasks = new Task[sizeSeasons];
221224

222225
for (uint i = 0; i < sizeSeasons; i++)
223226
{
224-
tasks[i] = _queryClient.Exec(
227+
tasks[i] = queryService.Exec(
225228
$"DECLARE $season_id AS Uint64; DECLARE $title AS Text;" +
226229
$"INSERT INTO {Tables.Seasons} (series_id, season_id, title) VALUES (3, $season_id, $title)",
227230
new Dictionary<string, YdbValue>
@@ -235,7 +238,7 @@ public async Task Stream_ReadingMore1000RowsFromChannel_ReturnChannelExecutePart
235238

236239
var currentSeason = 0;
237240

238-
await _queryClient.Stream(
241+
await queryService.Stream(
239242
$"SELECT title FROM {Tables.Seasons} ORDER BY series_id, season_id LIMIT {sizeSeasons} OFFSET 9",
240243
async stream =>
241244
{

0 commit comments

Comments
 (0)