Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ dotnet_diagnostic.CA1816.severity = none

# CA1859: Use concrete types when possible for improved performance
dotnet_diagnostic.CA1859.severity = none

# xUnit1051: Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken
dotnet_diagnostic.xUnit1051.severity = none

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand Down
5 changes: 5 additions & 0 deletions src/SuperSocket.Primitives/CertificateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ public X509Certificate GetCertificate()
filePath = Path.Combine(AppContext.BaseDirectory, filePath);
}

#if NET9_0_OR_GREATER
return X509CertificateLoader.LoadPkcs12FromFile(filePath, Password, KeyStorageFlags);
#else
return new X509Certificate2(filePath, Password, KeyStorageFlags);
#endif

}
else if (!string.IsNullOrEmpty(Thumbprint)) // Load certificate from certificate store
{
Expand Down
2 changes: 1 addition & 1 deletion test/SuperSocket.Benchmarks/SuperSocket.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<Description>SuperSocket benchmarking project for performance testing and analysis of core components using BenchmarkDotNet.</Description>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/SuperSocket.Tests/ClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
if (e.SocketErrorCode == SocketError.AccessDenied || e.SocketErrorCode == SocketError.AddressAlreadyInUse)
continue;

throw e;
throw;
}

break;
Expand Down Expand Up @@ -203,7 +203,7 @@
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(1));
var result = client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, localPort), cts.Token).AsTask();
int index = Task.WaitAny(new[] { result }, TimeSpan.FromSeconds(2));

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)

Check warning on line 206 in test/SuperSocket.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead. (https://xunit.net/xunit.analyzers/rules/xUnit1031)
var hasWaitedLongerThanTheCancellationToken = index == -1;

Assert.False(hasWaitedLongerThanTheCancellationToken);
Expand Down
6 changes: 3 additions & 3 deletions test/SuperSocket.Tests/CommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public async Task TestUnknownCommands(Type hostConfiguratorType)
commandOptions.AddCommand<ADD>();
commandOptions.RegisterUnknownPackageHandler<StringPackageInfo>(async (session, package, cancellationToken) =>
{
await session.SendAsync(Encoding.UTF8.GetBytes("X\r\n"));
await session.SendAsync(Encoding.UTF8.GetBytes("X\r\n"), cancellationToken);
});

// register all commands in one assembly
Expand Down Expand Up @@ -384,7 +384,7 @@ public COUNT(IPackageEncoder<string> encoder)

public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo package, CancellationToken cancellationToken)
{
await session.SendAsync(_encoder, "OK\r\n");
await session.SendAsync(_encoder, "OK\r\n", cancellationToken);
}
}

Expand All @@ -400,7 +400,7 @@ public COUNTDOWN(IPackageEncoder<string> encoder)

public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo package, CancellationToken cancellationToken)
{
await session.SendAsync(_encoder, "OK\r\n");
await session.SendAsync(_encoder, "OK\r\n", cancellationToken);
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/SuperSocket.Tests/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo packa
.Select(p => int.Parse(p))
.Sum();

await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n"));
await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n"), cancellationToken);
}
}

Expand All @@ -38,7 +38,7 @@ public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo packa
.Select(p => int.Parse(p))
.Aggregate((x, y) => x * y);

await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n"));
await session.SendAsync(Encoding.UTF8.GetBytes(result.ToString() + "\r\n"), cancellationToken);
}
}

Expand All @@ -58,7 +58,7 @@ public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo packa
.Aggregate((x, y) => x - y);

// encode the text message by encoder
await session.SendAsync(_encoder, result.ToString() + "\r\n");
await session.SendAsync(_encoder, result.ToString() + "\r\n", cancellationToken);
}
}

Expand Down
11 changes: 4 additions & 7 deletions test/SuperSocket.Tests/MainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
using SuperSocket.Server.Host;
using Xunit;

/// <summary>
/// Run selected test case by command
/// dotnet test --filter 'FullyQualifiedName=SuperSocket.Tests.SessionTest.TestCloseReason'
/// </summary>

namespace SuperSocket.Tests
{
/// <summary>
/// Run selected test case by command
/// dotnet test --filter 'FullyQualifiedName=SuperSocket.Tests.SessionTest.TestCloseReason'
/// </summary>
[Trait("Category", "Basic")]
public class MainTest : TestClassBase
{
Expand Down Expand Up @@ -800,8 +799,6 @@ public async Task TestMultipleServerHostWithConfigureServerOptions()
var server1 = default(IServer);
var server2 = default(IServer);

IHostEnvironment actualHostEvn = null;

var hostBuilder = MultipleServerHostBuilder.Create()
.AddServer<SuperSocketServiceA, TextPackageInfo, LinePipelineFilter>(builder =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo packa

Assert.Equal(packageHandlingContextAccessor.PackageHandlingContext.AppSession, session);
Assert.Equal(packageHandlingContextAccessor.PackageHandlingContext.PackageInfo, package);
await session.SendAsync(Encoding.UTF8.GetBytes(package.Body + "\r\n"));
await session.SendAsync(Encoding.UTF8.GetBytes(package.Body + "\r\n"), cancellationToken);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/SuperSocket.Tests/SessionContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SESS : IAsyncCommand<StringPackageInfo>
{
public async ValueTask ExecuteAsync(IAppSession session, StringPackageInfo package, CancellationToken cancellationToken)
{
await session.SendAsync(Encoding.UTF8.GetBytes(session.SessionID + "\r\n"));
await session.SendAsync(Encoding.UTF8.GetBytes(session.SessionID + "\r\n"), cancellationToken);
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/SuperSocket.Tests/WebSocket/WebSocketBasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public async Task TestEmptyMessage(Type hostConfiguratorType)

Assert.Equal(WebSocketState.Open, websocket.State);

var data = new byte[0];
var data = Array.Empty<byte>();
var segment = new ArraySegment<byte>(data, 0, data.Length);

await websocket.SendAsync(segment, WebSocketMessageType.Text, true, CancellationToken.None);
Expand Down Expand Up @@ -1206,7 +1206,7 @@ public async ValueTask ExecuteAsync(WebSocketSession session, StringPackageInfo
.Select(p => int.Parse(p))
.Sum();

await session.SendAsync(result.ToString());
await session.SendAsync(result.ToString(), cancellationToken);
}
}

Expand All @@ -1218,7 +1218,7 @@ public async ValueTask ExecuteAsync(WebSocketSession session, StringPackageInfo
.Select(p => int.Parse(p))
.Aggregate((x, y) => x * y);

await session.SendAsync(result.ToString());
await session.SendAsync(result.ToString(), cancellationToken);
}
}

Expand All @@ -1230,7 +1230,7 @@ public async ValueTask ExecuteAsync(WebSocketSession session, StringPackageInfo
.Select(p => int.Parse(p))
.Aggregate((x, y) => x - y);

await session.SendAsync(result.ToString());
await session.SendAsync(result.ToString(), cancellationToken);
}
}

Expand Down