Skip to content

Commit 0709f20

Browse files
committed
debug exception
1 parent 5c91daf commit 0709f20

6 files changed

Lines changed: 25 additions & 12 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Test
3535
run: |
3636
cd tests/SuperSocket.MySQL.Test
37-
dotnet test
37+
dotnet test --logger "console;verbosity=detailed"
3838
- name: Pack
3939
run: dotnet pack -c Release -p:PackageVersion=${{ steps.nbgv.outputs.NuGetPackageVersion }}.${{ github.run_number }} -p:Version=${{ steps.nbgv.outputs.NuGetPackageVersion }}.${{ github.run_number }} -p:AssemblyVersion=${{ steps.nbgv.outputs.AssemblyVersion }} -p:AssemblyFileVersion=${{ steps.nbgv.outputs.AssemblyFileVersion }} -p:AssemblyInformationalVersion=${{ steps.nbgv.outputs.AssemblyInformationalVersion }} /p:NoPackageAnalysis=true /p:IncludeReleaseNotes=false
4040
- name: Push

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
<PackageVersion Include="SuperSocket.Client" Version="2.0.2" />
88
<PackageVersion Include="SuperSocket.ProtoBase" Version="2.0.2" />
99
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
10-
<PackageVersion Include="xunit" Version="2.4.0" />
10+
<PackageVersion Include="xunit.v3" Version="1.0.1" />
1111
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.0" />
1212
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
1313
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
14+
<PackageVersion Include="Meziantou.Extensions.Logging.Xunit.v3" Version="1.0.0" />
1415
</ItemGroup>
1516
</Project>

src/SuperSocket.MySQL/MySQLConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class MySQLConnection : EasyClient<MySQLPacket>
3030
private readonly MySQLFilterContext filterContext;
3131

3232
public MySQLConnection(string host, int port, string userName, string password, ILogger logger = null)
33-
: this(new MySQLPacketFilter(MySQLPacketDecoder.ClientInstance), logger)
33+
: this(new MySQLPacketFilter(new MySQLPacketDecoder(MySQLPacketFactory.ClientInstance, logger)), logger)
3434
{
3535
_host = host ?? throw new ArgumentNullException(nameof(host));
3636
_port = port > 0 ? port : DefaultPort;

src/SuperSocket.MySQL/MySQLPacketDecoder.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
using System;
22
using System.Buffers;
33
using System.IO;
4+
using Microsoft.Extensions.Logging;
45
using SuperSocket.ProtoBase;
56

67
namespace SuperSocket.MySQL
78
{
89
internal class MySQLPacketDecoder : IPackageDecoder<MySQLPacket>
910
{
10-
public static MySQLPacketDecoder ClientInstance { get; }
11-
static MySQLPacketDecoder()
12-
{
13-
ClientInstance = new MySQLPacketDecoder(MySQLPacketFactory.ClientInstance);
14-
}
15-
11+
private readonly ILogger _logger;
1612
private readonly IMySQLPacketFactory _packetFactory;
1713

18-
private MySQLPacketDecoder(IMySQLPacketFactory packetFactory)
14+
public MySQLPacketDecoder(IMySQLPacketFactory packetFactory, ILogger logger)
1915
{
2016
_packetFactory = packetFactory ?? throw new ArgumentNullException(nameof(packetFactory));
17+
this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
2118
}
2219

2320
public MySQLPacket Decode(ref ReadOnlySequence<byte> buffer, object context)
@@ -44,6 +41,8 @@ public MySQLPacket Decode(ref ReadOnlySequence<byte> buffer, object context)
4441
packetType = (int)packetTypeByte;
4542
}
4643

44+
_logger.LogDebug("Decoding MySQL packet with sequence ID {SequenceId} and type {PacketType}", sequenceId, packetType);
45+
4746
var package = _packetFactory.Create(packetType);
4847

4948
package = package.Decode(ref reader, context);

tests/SuperSocket.MySQL.Test/MySQLIntegrationTest.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Threading.Tasks;
44
using Xunit;
55
using SuperSocket.MySQL;
6+
using Microsoft.Extensions.Logging;
7+
using Meziantou.Extensions.Logging.Xunit.v3;
68

79
namespace SuperSocket.MySQL.Test
810
{
@@ -12,6 +14,13 @@ namespace SuperSocket.MySQL.Test
1214
/// </summary>
1315
public class MySQLIntegrationTest
1416
{
17+
private protected readonly ITestOutputHelper outputHelper;
18+
19+
public MySQLIntegrationTest(ITestOutputHelper outputHelper)
20+
{
21+
this.outputHelper = outputHelper;
22+
}
23+
1524
[Fact]
1625
[Trait("Category", "Integration")]
1726
public async Task MySQLConnection_CompleteHandshakeFlow_ShouldAuthenticate()
@@ -40,7 +49,10 @@ public async Task MySQLConnection_CompleteHandshakeFlow_ShouldAuthenticate()
4049
public async Task MySQLConnection_InvalidCredentials_ShouldFailHandshake()
4150
{
4251
// Arrange
43-
var connection = new MySQLConnection(TestConst.Host, TestConst.DefaultPort, "nonexistent_user", "wrong_password");
52+
var loggerFactory = new LoggerFactory();
53+
loggerFactory.AddProvider(new XUnitLoggerProvider(this.outputHelper));
54+
55+
var connection = new MySQLConnection(TestConst.Host, TestConst.DefaultPort, "nonexistent_user", "wrong_password", loggerFactory.CreateLogger(nameof(MySQLConnection_InvalidCredentials_ShouldFailHandshake)));
4456

4557
// Act & Assert
4658
var exception = await Assert.ThrowsAsync<InvalidOperationException>(

tests/SuperSocket.MySQL.Test/SuperSocket.MySQL.Test.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.NET.Test.Sdk" />
10-
<PackageReference Include="xunit" />
10+
<PackageReference Include="xunit.v3" />
1111
<PackageReference Include="xunit.runner.visualstudio" />
12+
<PackageReference Include="Meziantou.Extensions.Logging.Xunit.v3" />
1213
<PackageReference Include="Microsoft.Extensions.Logging" />
1314
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
1415
</ItemGroup>

0 commit comments

Comments
 (0)