Skip to content

Commit

Permalink
added unit tests for Ketsrel support
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Mar 24, 2024
1 parent 93d1878 commit 03d1d85
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/SuperSocket.Tests/KestralConnectionHostConfigurator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using SuperSocket;
using SuperSocket.Connection;
using SuperSocket.Server.Abstractions;
using SuperSocket.Server.Abstractions.Host;
using SuperSocket.Client;
using SuperSocket.ProtoBase;
using SuperSocket.Kestrel;

namespace SuperSocket.Tests
{
public class KestralConnectionHostConfigurator : RegularHostConfigurator
{
public KestralConnectionHostConfigurator()
: base()
{
}

public override void Configure(ISuperSocketHostBuilder hostBuilder)
{
base.Configure(hostBuilder);
hostBuilder.UseKestrelPipeConnection();
}
}
}
40 changes: 40 additions & 0 deletions test/SuperSocket.Tests/MainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using System.Linq;
using System.Collections.Generic;
using System.Security.Authentication;
using SuperSocket.Kestrel;
using System.Threading;

/// <summary>
/// Run selected test case by command
Expand Down Expand Up @@ -170,6 +172,7 @@ public async Task TestSecurityOptions(string security, SslProtocols protocols, b

[Theory]
[InlineData(typeof(RegularHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
[InlineData(typeof(UdpHostConfigurator))]
public async Task TestSessionHandlers(Type hostConfiguratorType)
{
Expand Down Expand Up @@ -336,9 +339,44 @@ public async Task TestConfigureSocketOptions()
}
}

[Theory]
[InlineData(typeof(RegularHostConfigurator), typeof(TcpPipeConnection))]
[InlineData(typeof(SecureHostConfigurator), typeof(StreamPipeConnection))]
//[InlineData(typeof(UdpHostConfigurator), typeof(UdpConnectionStream))]
[InlineData(typeof(KestralConnectionHostConfigurator), typeof(KestrelPipeConnection))]
public async Task TestConnectionType(Type hostConfiguratorType, Type connectionType)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);
var connection = default(IConnection);
var resetEvent = new ManualResetEvent(false);

using (var server = CreateSocketServerBuilder<TextPackageInfo, LinePipelineFilter>(hostConfigurator)
.UseSessionHandler(onConnected: (session) =>
{
connection = session.Connection;
resetEvent.Set();
return ValueTask.CompletedTask;
}).BuildAsServer() as IServer)
{
Assert.True(await server.StartAsync());
Assert.Equal(0, server.SessionCount);

using (var socket = CreateClient(hostConfigurator))
using (var socketStream = await hostConfigurator.GetClientStream(socket))
{
resetEvent.WaitOne(5000);
}

await server.StopAsync();
}

Assert.IsType(connectionType, connection);
}

[Theory]
[InlineData(typeof(RegularHostConfigurator))]
[InlineData(typeof(SecureHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
public async Task TestConsoleProtocol(Type hostConfiguratorType)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);
Expand Down Expand Up @@ -370,6 +408,7 @@ public async Task TestConsoleProtocol(Type hostConfiguratorType)
[Theory]
[InlineData(typeof(RegularHostConfigurator))]
[InlineData(typeof(SecureHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
public async Task TestCloseAfterSend(Type hostConfiguratorType)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);
Expand Down Expand Up @@ -403,6 +442,7 @@ public async Task TestCloseAfterSend(Type hostConfiguratorType)
[InlineData(typeof(RegularHostConfigurator))]
[InlineData(typeof(SecureHostConfigurator))]
[InlineData(typeof(UdpHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
public async Task TestMultipleHostStartup(Type hostConfiguratorType)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);
Expand Down
5 changes: 5 additions & 0 deletions test/SuperSocket.Tests/ProtocolTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected ProtocolTestBase(ITestOutputHelper outputHelper) : base(outputHelper)
[InlineData(typeof(GzipSecureHostConfigurator))]
[InlineData(typeof(GzipHostConfigurator))]
[InlineData(typeof(UdpHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
public virtual async Task TestNormalRequest(Type hostConfiguratorType)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 36 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestNormalRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);
Expand Down Expand Up @@ -65,6 +66,7 @@ public virtual async Task TestNormalRequest(Type hostConfiguratorType)
[InlineData(typeof(UdpHostConfigurator))]
[InlineData(typeof(GzipSecureHostConfigurator))]
[InlineData(typeof(GzipHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
public virtual async Task TestMiddleBreak(Type hostConfiguratorType)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 70 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestMiddleBreak' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);
Expand Down Expand Up @@ -100,6 +102,7 @@ public virtual async Task TestMiddleBreak(Type hostConfiguratorType)
[InlineData(typeof(UdpHostConfigurator))]
[InlineData(typeof(GzipSecureHostConfigurator))]
[InlineData(typeof(GzipHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
public virtual async Task TestFragmentRequest(Type hostConfiguratorType)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 106 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestFragmentRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);
Expand Down Expand Up @@ -140,6 +143,7 @@ public virtual async Task TestFragmentRequest(Type hostConfiguratorType)
[InlineData(typeof(UdpHostConfigurator))]
[InlineData(typeof(GzipSecureHostConfigurator))]
[InlineData(typeof(GzipHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
public virtual async Task TestBatchRequest(Type hostConfiguratorType)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 147 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestBatchRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)
{
var hostConfigurator = CreateObject<IHostConfigurator>(hostConfiguratorType);
Expand Down Expand Up @@ -187,6 +191,7 @@ public virtual async Task TestBatchRequest(Type hostConfiguratorType)
[InlineData(typeof(SecureHostConfigurator))]
[InlineData(typeof(GzipSecureHostConfigurator))]
[InlineData(typeof(GzipHostConfigurator))]
[InlineData(typeof(KestralConnectionHostConfigurator))]
//[InlineData(typeof(UdpHostConfigurator))]
public virtual async Task TestBreakRequest(Type hostConfiguratorType)

Check warning on line 196 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestBreakRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 196 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Public method 'TestBreakRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 196 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestBreakRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 196 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Public method 'TestBreakRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 196 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestBreakRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)

Check warning on line 196 in test/SuperSocket.Tests/ProtocolTestBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Public method 'TestBreakRequest' on test class 'ProtocolTestBase' should be marked as a Theory. (https://xunit.github.io/xunit.analyzers/rules/xUnit1013)
{
Expand Down
1 change: 1 addition & 0 deletions test/SuperSocket.Tests/SuperSocket.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ProjectReference Include="../../src/SuperSocket.Client/SuperSocket.Client.csproj" />
<ProjectReference Include="../../src/SuperSocket.Udp/SuperSocket.Udp.csproj" />
<ProjectReference Include="../../src/SuperSocket.Http/SuperSocket.Http.csproj" />
<ProjectReference Include="../../src/SuperSocket.Kestrel/SuperSocket.Kestrel.csproj" />
<ProjectReference Include="../SuperSocket.Tests.Command/SuperSocket.Tests.Command.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 03d1d85

Please sign in to comment.