-
-
Notifications
You must be signed in to change notification settings - Fork 363
refactor(ITcpSocketFactory): add GetOrCreate extension method #6277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
# Conflicts: # test/UnitTest/Services/TcpSocketFactoryTest.cs
Reviewer's GuideRefactors the socket factory to identify clients by name and use IPEndPoint for endpoint definition, updating interface signatures, default implementation logic, unit tests, and adding an extension to convert IP/port into IPEndPoint. Class diagram for refactored ITcpSocketFactory and extensionclassDiagram
class ITcpSocketFactory {
+ITcpSocketClient GetOrCreate(string name, IPEndPoint endPoint)
+ITcpSocketClient? Remove(string name)
}
class DefaultTcpSocketFactory {
+ITcpSocketClient GetOrCreate(string name, IPEndPoint endPoint)
+ITcpSocketClient? Remove(string name)
-ConcurrentDictionary<string, ITcpSocketClient> _pool
}
class ITcpSocketFactoryExtensions {
+static ITcpSocketClient GetOrCreate(ITcpSocketFactory factory, string name, string ipAddress, int port)
}
ITcpSocketFactory <|.. DefaultTcpSocketFactory
ITcpSocketFactoryExtensions ..> ITcpSocketFactory : extension
DefaultTcpSocketFactory o-- ITcpSocketClient
ITcpSocketFactoryExtensions ..> Utility : uses
class Utility {
+static IPEndPoint ConvertToIpEndPoint(string ipAddress, int port)
}
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ArgoZhang - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Services/TcpSocket/DefaultTcpSocketFactory.cs:19` </location>
<code_context>
private readonly ConcurrentDictionary<string, ITcpSocketClient> _pool = new();
- public ITcpSocketClient GetOrCreate(string host, int port = 0)
+ public ITcpSocketClient GetOrCreate(string name, IPEndPoint endPoint)
{
- return _pool.GetOrAdd($"{host}:{port}", key =>
</code_context>
<issue_to_address>
Potential for name and endpoint mismatch leading to unexpected client reuse.
Since the client pool uses only 'name' as the key, using the same name with different endpoints will always return the client for the first endpoint. This may cause unexpected behavior if the endpoint is expected to be unique. Please document this clearly or enforce unique name-endpoint pairs.
</issue_to_address>
### Comment 2
<location> `test/UnitTest/Services/TcpSocketFactoryTest.cs:39` </location>
<code_context>
+ var client4 = factory.GetOrCreate("demo2", "256.0.0.1", 0);
- var client5 = factory.Remove("256.0.0.1", 0);
+ var client5 = factory.Remove("demo2");
Assert.Equal(client4, client5);
Assert.NotNull(client5);
</code_context>
<issue_to_address>
Missing test for Remove with non-existent or invalid names.
Add tests for Remove when called with non-existent names, null, or empty strings to ensure it returns null and handles these cases without exceptions.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6277 +/- ##
========================================
Coverage 99.99% 100.00%
========================================
Files 712 713 +1
Lines 31397 31400 +3
Branches 4437 4437
========================================
+ Hits 31396 31400 +4
+ Partials 1 0 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6276
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Refactor the TCP socket factory API to use named identifiers and IPEndPoint parameters, add a convenient extension overload, and update tests to reflect these changes
New Features:
Enhancements:
Tests: