Conversation
Improve race condition safety by using atomic methods Improve dispose processes of the server and the client Improve error handling Add LogLevel property to the server options
Add WebSocketConnectionException
…lse to all awaited methods in the library
There was a problem hiding this comment.
Pull Request Overview
This PR adds integration tests to verify WebSocket connection stability and implements race condition safety improvements across the library. The main focus is on adding comprehensive integration testing capabilities while improving thread safety and async operation handling.
- Added new integration test project with server and client test scenarios for connection stability
- Improved race condition safety using atomic operations (Interlocked) for state management
- Added ConfigureAwait(false) to all async operations in the library to prevent deadlocks
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Jung.SimpleWebSocket.sln | Added integration test project to solution |
| tests/Jung.SimpleWebSocket.IntegrationTests/Jung.SimpleWebSocket.IntegrationTests.csproj | New integration test project configuration |
| tests/Jung.SimpleWebSocket.IntegrationTests/Program.cs | Main entry point for running integration tests |
| tests/Jung.SimpleWebSocket.IntegrationTests/ProcedureProvider.cs | Test procedure discovery and execution framework |
| tests/Jung.SimpleWebSocket.IntegrationTests/TestProcedure.cs | Test procedure definition class |
| tests/Jung.SimpleWebSocket.IntegrationTests/Tests/BaseTest.cs | Base class for integration tests |
| tests/Jung.SimpleWebSocket.IntegrationTests/Tests/TestInformationAttribute.cs | Attribute for test metadata |
| tests/Jung.SimpleWebSocket.IntegrationTests/Tests/DisplayEventsServerTest.cs | Server-side event display test |
| tests/Jung.SimpleWebSocket.IntegrationTests/Tests/SendMessagesLoopTest.cs | Client stability test with message sending |
| src/Jung.SimpleWebSocket/SimpleWebSocketServer.cs | Enhanced thread safety and ConfigureAwait implementation |
| src/Jung.SimpleWebSocket/SimpleWebSocketClient.cs | Enhanced thread safety and ConfigureAwait implementation |
| src/Jung.SimpleWebSocket/Models/SimpleWebSocketServerOptions.cs | Added LogLevel configuration option |
| src/Jung.SimpleWebSocket/Models/EventArguments/ClientDisconnectedArgs.cs | Updated to handle nullable closing status |
| src/Jung.SimpleWebSocket/Exceptions/WebSocketConnectionException.cs | New exception for connection-specific errors |
| src/Jung.SimpleWebSocket/Flows/ClientHandlingFlow.cs | Added ConfigureAwait to async operations |
| src/Jung.SimpleWebSocket/Utility/AsyncEventRaiser.cs | Added ConfigureAwait to async operations |
| src/Jung.SimpleWebSocket/Wrappers/NetworkStreamWrapper.cs | Added ConfigureAwait to async operations |
| src/Jung.SimpleWebSocket/Wrappers/TcpListenerWrapper.cs | Added ConfigureAwait to async operations |
| src/Jung.SimpleWebSocket/Wrappers/WebSocketUpgradeHandler.cs | Added ConfigureAwait to async operations |
| tests/Jung.SimpleWebSocket.UnitTests/SimpleWebSocketTest.cs | Fixed logger type and null coalescing operator usage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| /// <para>0 = false, 1 = true</para>s | ||
| /// </summary> | ||
| private int _disposed; | ||
|
|
||
| /// <summary> | ||
| /// A flag indicating whether the server is disposing. | ||
| /// <para>0 = false, 1 = true</para>s |
There was a problem hiding this comment.
Removed extraneous 's' at the end of the comment.
| /// <para>0 = false, 1 = true</para>s | |
| /// </summary> | |
| private int _disposed; | |
| /// <summary> | |
| /// A flag indicating whether the server is disposing. | |
| /// <para>0 = false, 1 = true</para>s | |
| /// <para>0 = false, 1 = true</para> | |
| /// </summary> | |
| private int _disposed; | |
| /// <summary> | |
| /// A flag indicating whether the server is disposing. | |
| /// <para>0 = false, 1 = true</para> |
|
|
||
| /// <summary> | ||
| /// A flag indicating whether the server is disposing. | ||
| /// <para>0 = false, 1 = true</para>s |
There was a problem hiding this comment.
Removed extraneous 's' at the end of the comment.
| /// <para>0 = false, 1 = true</para>s | |
| /// <para>0 = false, 1 = true</para> |
| await client.WebSocket.CloseAsync(WebSocketCloseStatus.EndpointUnavailable, "Server is shutting down", linkedTokenSource.Token); | ||
| ActiveClients.TryRemove(client.Id, out _); | ||
| client?.Dispose(); | ||
| // Ignore the exception, because it's no the servers problem if a client does not close the connection |
There was a problem hiding this comment.
Corrected 'no' to 'not' in the comment.
| // Ignore the exception, because it's no the servers problem if a client does not close the connection | |
| // Ignore the exception, because it's not the server's problem if a client does not close the connection |
| { | ||
| try | ||
| { | ||
| if(!client.IsConnected) |
There was a problem hiding this comment.
Missing space after 'if' keyword. Should be 'if (!client.IsConnected)' following C# coding conventions.
| if(!client.IsConnected) | |
| if (!client.IsConnected) |
Add integration tests to the project that simulate a server and a client to test the connection and web socket upgrade process and the stability of the connection.
Improve race condition safety
Add ConfigureAwait with continueOnCapturedContext parameter set to false to all awaited methods in the library