Skip to content

Commit

Permalink
Add test for GracefulShutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
XmasApple committed Oct 19, 2023
1 parent c03a99a commit e3b3199
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/Ydb.Sdk/src/Services/Table/ExecuteDataQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public async Task<ExecuteDataQueryResponse> ExecuteDataQuery(

var status = UnpackOperation(response.Data.Operation, out ExecuteQueryResult? resultProto);
OnResponseStatus(status);
OnResponseTrailers(response.Trailers);

var txState = TransactionState.Unknown;
Transaction? tx = null;
Expand Down
1 change: 0 additions & 1 deletion src/Ydb.Sdk/src/Services/Table/ExecuteSchemeQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public async Task<ExecuteSchemeQueryResponse> ExecuteSchemeQuery(

var status = UnpackOperation(response.Data.Operation);
OnResponseStatus(status);
OnResponseTrailers(response.Trailers);

return new ExecuteSchemeQueryResponse(status);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Ydb.Sdk/src/Services/Table/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,20 @@ protected virtual void Dispose(bool disposing)
_disposed = true;
}

internal Task<Driver.UnaryResponse<TResponse>> UnaryCall<TRequest, TResponse>(
internal async Task<Driver.UnaryResponse<TResponse>> UnaryCall<TRequest, TResponse>(
Method<TRequest, TResponse> method,
TRequest request,
RequestSettings settings)
where TRequest : class
where TResponse : class
{
return Driver.UnaryCall(
var response = await Driver.UnaryCall(
method: method,
request: request,
settings: settings,
preferredEndpoint: Endpoint
);
OnResponseTrailers(response.Trailers);
return response;
}
}
93 changes: 93 additions & 0 deletions src/Ydb.Sdk/tests/Table/TestGracefulShutdown.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
using Xunit.Abstractions;
using Ydb.Sdk.Services.Table;

namespace Ydb.Sdk.Tests.Table;

[Trait("Category", "Integration")]
public class TestGracefulShutdown
{
private readonly ITestOutputHelper _testOutputHelper;

Check warning on line 12 in src/Ydb.Sdk/tests/Table/TestGracefulShutdown.cs

View workflow job for this annotation

GitHub Actions / Inspection

"[NotAccessedField.Local] Field '_testOutputHelper' is assigned but its value is never used" on /home/runner/work/ydb-dotnet-sdk/ydb-dotnet-sdk/src/Ydb.Sdk/tests/Table/TestGracefulShutdown.cs(12,297)
private readonly ILoggerFactory _loggerFactory;

private readonly DriverConfig _driverConfig = new(
endpoint: "grpc://localhost:2136",
database: "/local"
);

private const string ShutdownUrl = "http://localhost:8765/actors/kqp_proxy?force_shutdown=all";

public TestGracefulShutdown(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
_loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance;
}

[Fact]
public async Task Test()
{
await using var driver = await Driver.CreateInitialized(_driverConfig, _loggerFactory);
using var tableClient = new TableClient(driver);


var session1 = "";
await tableClient.SessionExec(
async session =>
{
session1 = session.Id;
return await session.ExecuteDataQuery("SELECT 1", TxControl.BeginSerializableRW().Commit());
}
);

// _testOutputHelper.WriteLine(session1);
await Task.Delay(1000);

var session2 = "";
await tableClient.SessionExec(
async session =>
{
session2 = session.Id;
return await session.ExecuteDataQuery("SELECT 1", TxControl.BeginSerializableRW().Commit());
}
);

// _testOutputHelper.WriteLine(session2);
await Task.Delay(1000);


// control check
Assert.NotEqual("", session1);
Assert.Equal(session1, session2);

// SHUTDOWN
using var httpClient = new HttpClient();
await httpClient.GetAsync(ShutdownUrl);
await Task.Delay(1000);

// new session
var session3 = "";
await tableClient.SessionExec(
async session =>
{
session3 = session.Id;
return await session.ExecuteDataQuery("SELECT 1", TxControl.BeginSerializableRW().Commit());
}
);

Assert.Equal(session2, session3);

var session4 = "";
await tableClient.SessionExec(
async session =>
{
session4 = session.Id;
return await session.ExecuteDataQuery("SELECT 1", TxControl.BeginSerializableRW().Commit());
}
);

Assert.NotEqual("", session3);
Assert.NotEqual(session3, session4);
}
}

0 comments on commit e3b3199

Please sign in to comment.