Conversation
审阅者指南(在小型 PR 中折叠显示)审阅者指南更新测试以使用新的 McPing 服务工厂,在记录器测试中现代化日志记录器的释放与配置方式,并在清理未使用代码/using 的同时,为 SemVer 解析测试新增一个预发布版本用例。 LoggerTest.TestHeavyWrite 的时序图:带异步释放和取消支持sequenceDiagram
actor MSTestRunner
participant LoggerTest
participant Logger
participant TaskWorker1
participant TaskWorker2
MSTestRunner->>LoggerTest: TestHeavyWrite()
activate LoggerTest
LoggerTest->>LoggerTest: create LoggerConfiguration(tempPath)
LoggerTest->>Logger: new Logger(loggerConfiguration)
activate Logger
loop create tasks
LoggerTest->>TaskWorker1: start Task(Info loop, CancellationToken)
activate TaskWorker1
LoggerTest->>TaskWorker2: start Task(Info loop, CancellationToken)
activate TaskWorker2
end
loop per message in TaskWorker1
TaskWorker1->>Logger: Info(message)
end
loop per message in TaskWorker2
TaskWorker2->>Logger: Info(message)
end
TaskWorker1-->>LoggerTest: task completed or canceled
deactivate TaskWorker1
TaskWorker2-->>LoggerTest: task completed or canceled
deactivate TaskWorker2
LoggerTest->>LoggerTest: Task.WhenAll(tasks)
LoggerTest->>Logger: DisposeAsync()
deactivate Logger
Logger-->>LoggerTest: disposal complete
deactivate LoggerTest
LoggerTest-->>MSTestRunner: TestHeavyWrite completed
更新后 McPing、Logger 和 SemVer 测试用法的类图classDiagram
class McPingTest {
+PingTest() Task
}
class McPingServiceFactory {
+CreateService(host string, port int) McPingService
}
class McPingService {
+PingAsync() Task
}
class LoggerTest {
+TestSimpleWrite() void
+TestHeavyWrite() Task
+TestContext TestContext
}
class LoggerConfiguration {
+LoggerConfiguration(path string)
+LoggerConfiguration(path string, segmentMode LoggerSegmentMode, maxSizeBytes long)
+Path string
+SegmentMode LoggerSegmentMode
+MaxSizeBytes long
}
class Logger {
+Logger(configuration LoggerConfiguration)
+Info(message string) void
+Dispose() void
+DisposeAsync() ValueTask
}
class TestContext {
+CancellationToken CancellationToken
}
class SemVerTest {
+TestParse() void
}
class SemVer {
+Major int
+Minor int
+Patch int
+Prerelease string
+Parse(input string) SemVer
+ToString() string
+CompareTo(other SemVer) int
}
McPingTest ..> McPingServiceFactory : uses
McPingServiceFactory ..> McPingService : creates
McPingTest ..> McPingService : uses
LoggerTest ..> LoggerConfiguration : creates
LoggerTest ..> Logger : uses
LoggerTest ..> TestContext : uses
SemVerTest ..> SemVer : uses
Logger --> LoggerConfiguration : has
SemVerTest ..> SemVer : parses_and_compares
文件级变更
技巧与命令与 Sourcery 交互
自定义你的使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates tests to use the new McPing service factory, modernizes logger disposal and configuration in logger tests, and extends SemVer parsing tests with an additional prerelease version case while cleaning up unused code/usings. Sequence diagram for LoggerTest.TestHeavyWrite with async disposal and cancellationsequenceDiagram
actor MSTestRunner
participant LoggerTest
participant Logger
participant TaskWorker1
participant TaskWorker2
MSTestRunner->>LoggerTest: TestHeavyWrite()
activate LoggerTest
LoggerTest->>LoggerTest: create LoggerConfiguration(tempPath)
LoggerTest->>Logger: new Logger(loggerConfiguration)
activate Logger
loop create tasks
LoggerTest->>TaskWorker1: start Task(Info loop, CancellationToken)
activate TaskWorker1
LoggerTest->>TaskWorker2: start Task(Info loop, CancellationToken)
activate TaskWorker2
end
loop per message in TaskWorker1
TaskWorker1->>Logger: Info(message)
end
loop per message in TaskWorker2
TaskWorker2->>Logger: Info(message)
end
TaskWorker1-->>LoggerTest: task completed or canceled
deactivate TaskWorker1
TaskWorker2-->>LoggerTest: task completed or canceled
deactivate TaskWorker2
LoggerTest->>LoggerTest: Task.WhenAll(tasks)
LoggerTest->>Logger: DisposeAsync()
deactivate Logger
Logger-->>LoggerTest: disposal complete
deactivate LoggerTest
LoggerTest-->>MSTestRunner: TestHeavyWrite completed
Class diagram for updated test usage of McPing, Logger, and SemVerclassDiagram
class McPingTest {
+PingTest() Task
}
class McPingServiceFactory {
+CreateService(host string, port int) McPingService
}
class McPingService {
+PingAsync() Task
}
class LoggerTest {
+TestSimpleWrite() void
+TestHeavyWrite() Task
+TestContext TestContext
}
class LoggerConfiguration {
+LoggerConfiguration(path string)
+LoggerConfiguration(path string, segmentMode LoggerSegmentMode, maxSizeBytes long)
+Path string
+SegmentMode LoggerSegmentMode
+MaxSizeBytes long
}
class Logger {
+Logger(configuration LoggerConfiguration)
+Info(message string) void
+Dispose() void
+DisposeAsync() ValueTask
}
class TestContext {
+CancellationToken CancellationToken
}
class SemVerTest {
+TestParse() void
}
class SemVer {
+Major int
+Minor int
+Patch int
+Prerelease string
+Parse(input string) SemVer
+ToString() string
+CompareTo(other SemVer) int
}
McPingTest ..> McPingServiceFactory : uses
McPingServiceFactory ..> McPingService : creates
McPingTest ..> McPingService : uses
LoggerTest ..> LoggerConfiguration : creates
LoggerTest ..> Logger : uses
LoggerTest ..> TestContext : uses
SemVerTest ..> SemVer : uses
Logger --> LoggerConfiguration : has
SemVerTest ..> SemVer : parses_and_compares
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我发现了 2 个问题,并留下了一些高层次的反馈:
- 在
SemVerTest中,Assert.IsGreaterThan(t5, t4);无法使用标准 MSTest 的AssertAPI 进行编译;建议改为使用Assert.IsTrue(t5.CompareTo(t4) > 0);或者自定义比较方法来进行断言。 - 在
LoggerTest.TestHeavyWrite中,仅将TestContext.CancellationToken传给Task.Run并不能协作式地取消内部的日志循环;如果你希望测试可以被取消,那么需要在循环内部检查该 token,或使用在执行过程中会观察该 token 的 API。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- In `SemVerTest`, `Assert.IsGreaterThan(t5, t4);` will not compile with the standard MSTest `Assert` API; consider asserting via `Assert.IsTrue(t5.CompareTo(t4) > 0);` or a custom comparer method instead.
- In `LoggerTest.TestHeavyWrite`, passing `TestContext.CancellationToken` only to `Task.Run` does not cooperatively cancel the inner logging loop; if you intend the test to be cancellable, also check the token inside the loop or use an API that observes the token during execution.
## Individual Comments
### Comment 1
<location path="PCL.Core.Test/Minecraft/McPing.cs" line_range="22" />
<code_context>
Console.WriteLine(res.Description);
- using var ping1 = new McPing("mc233.cn", 25565);
+ using var ping1 = McPingServiceFactory.CreateService("mc.233.cn", 25565);
res = await ping1.PingAsync();
Assert.IsNotNull(res);
</code_context>
<issue_to_address>
**issue (bug_risk):** Host name changed from `mc233.cn` to `mc.233.cn` may be an unintended typo.
The original test used "mc233.cn" (no dot after `mc`), while the new value is "mc.233.cn". This may be an accidental change and could break DNS resolution. If this host change is intentional, that’s fine; otherwise, please revert to the original string.
</issue_to_address>
### Comment 2
<location path="PCL.Core.Test/SemVerTest.cs" line_range="49" />
<code_context>
+ var t5 = SemVer.Parse("v2.14.5-beta.1.2147483647");
+ Assert.IsNotNull(t5);
+ Console.WriteLine(t5.ToString());
+ Assert.IsGreaterThan(t5, t4);
}
}
</code_context>
<issue_to_address>
**issue (testing):** Use a MSTest-compatible assertion instead of `Assert.IsGreaterThan`, which is not available in MSTest.
`Assert.IsGreaterThan` is defined in other frameworks (e.g., NUnit), not in MSTest, so this test won’t compile unless you’ve added a custom extension. In MSTest, use something like `Assert.IsTrue(t5.CompareTo(t4) > 0);` or `Assert.IsTrue(t5 > t4);` (if the comparison operators are overloaded) instead.
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- In
SemVerTest,Assert.IsGreaterThan(t5, t4);will not compile with the standard MSTestAssertAPI; consider asserting viaAssert.IsTrue(t5.CompareTo(t4) > 0);or a custom comparer method instead. - In
LoggerTest.TestHeavyWrite, passingTestContext.CancellationTokenonly toTask.Rundoes not cooperatively cancel the inner logging loop; if you intend the test to be cancellable, also check the token inside the loop or use an API that observes the token during execution.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `SemVerTest`, `Assert.IsGreaterThan(t5, t4);` will not compile with the standard MSTest `Assert` API; consider asserting via `Assert.IsTrue(t5.CompareTo(t4) > 0);` or a custom comparer method instead.
- In `LoggerTest.TestHeavyWrite`, passing `TestContext.CancellationToken` only to `Task.Run` does not cooperatively cancel the inner logging loop; if you intend the test to be cancellable, also check the token inside the loop or use an API that observes the token during execution.
## Individual Comments
### Comment 1
<location path="PCL.Core.Test/Minecraft/McPing.cs" line_range="22" />
<code_context>
Console.WriteLine(res.Description);
- using var ping1 = new McPing("mc233.cn", 25565);
+ using var ping1 = McPingServiceFactory.CreateService("mc.233.cn", 25565);
res = await ping1.PingAsync();
Assert.IsNotNull(res);
</code_context>
<issue_to_address>
**issue (bug_risk):** Host name changed from `mc233.cn` to `mc.233.cn` may be an unintended typo.
The original test used "mc233.cn" (no dot after `mc`), while the new value is "mc.233.cn". This may be an accidental change and could break DNS resolution. If this host change is intentional, that’s fine; otherwise, please revert to the original string.
</issue_to_address>
### Comment 2
<location path="PCL.Core.Test/SemVerTest.cs" line_range="49" />
<code_context>
+ var t5 = SemVer.Parse("v2.14.5-beta.1.2147483647");
+ Assert.IsNotNull(t5);
+ Console.WriteLine(t5.ToString());
+ Assert.IsGreaterThan(t5, t4);
}
}
</code_context>
<issue_to_address>
**issue (testing):** Use a MSTest-compatible assertion instead of `Assert.IsGreaterThan`, which is not available in MSTest.
`Assert.IsGreaterThan` is defined in other frameworks (e.g., NUnit), not in MSTest, so this test won’t compile unless you’ve added a custom extension. In MSTest, use something like `Assert.IsTrue(t5.CompareTo(t4) > 0);` or `Assert.IsTrue(t5 > t4);` (if the comparison operators are overloaded) instead.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| Console.WriteLine(res.Description); | ||
|
|
||
| using var ping1 = new McPing("mc233.cn", 25565); | ||
| using var ping1 = McPingServiceFactory.CreateService("mc.233.cn", 25565); |
There was a problem hiding this comment.
issue (bug_risk): 将主机名从 mc233.cn 改为 mc.233.cn 可能是无意的拼写错误。
原始测试使用的是 "mc233.cn"(mc 后面没有点),而新值是 "mc.233.cn"。这可能是一次无意的修改,并可能导致 DNS 解析失败。如果确实是有意更换主机,那就没问题;否则请恢复为原始字符串。
Original comment in English
issue (bug_risk): Host name changed from mc233.cn to mc.233.cn may be an unintended typo.
The original test used "mc233.cn" (no dot after mc), while the new value is "mc.233.cn". This may be an accidental change and could break DNS resolution. If this host change is intentional, that’s fine; otherwise, please revert to the original string.
There was a problem hiding this comment.
这应当是正确的。
https://namemc.com/server/mc233.cn 得到服务器信息
https://namemc.com/server/mc.233.cn 得到大写的 Error: 404 (Not Found)
There was a problem hiding this comment.
了解了,感谢补充这两个链接的验证信息。
从你提供的结果来看:
mc233.cn可以正常解析并获取服务器信息mc.233.cn返回 404 错误
这样可以确定当前改动里把主机名改成 mc.233.cn 确实会导致目标服务器不可用,是一个回归问题。
建议在这个测试里把主机名改回原来的:
using var ping1 = McPingServiceFactory.CreateService("mc233.cn", 25565);如果后续有需要替换或新增其他测试服务器,也可以在单独的 commit 里做,这个 PR 里就专注于修复编译问题和 API 变更适配。
| var t5 = SemVer.Parse("v2.14.5-beta.1.2147483647"); | ||
| Assert.IsNotNull(t5); | ||
| Console.WriteLine(t5.ToString()); | ||
| Assert.IsGreaterThan(t5, t4); |
There was a problem hiding this comment.
issue (testing): 请使用与 MSTest 兼容的断言来替代 Assert.IsGreaterThan,因为 MSTest 中没有该方法。
Assert.IsGreaterThan 是在其他测试框架(例如 NUnit)中定义的,而不是在 MSTest 中定义的,因此除非你添加了自定义扩展,否则该测试将无法编译。在 MSTest 中,可以使用类似 Assert.IsTrue(t5.CompareTo(t4) > 0); 或 Assert.IsTrue(t5 > t4);(如果已重载比较运算符)之类的断言语句来代替。
Original comment in English
issue (testing): Use a MSTest-compatible assertion instead of Assert.IsGreaterThan, which is not available in MSTest.
Assert.IsGreaterThan is defined in other frameworks (e.g., NUnit), not in MSTest, so this test won’t compile unless you’ve added a custom extension. In MSTest, use something like Assert.IsTrue(t5.CompareTo(t4) > 0); or Assert.IsTrue(t5 > t4); (if the comparison operators are overloaded) instead.
Summary by Sourcery
使测试与更新后的网络、日志记录和语义化版本(SemVer)API 对齐,并为新的 SemVer 场景增加测试覆盖。
Bug 修复:
LoggerConfigurationAPI,并采用正确的异步释放(async disposal)语义以防止编译问题。测试:
PingOldAsyncAPI 的过时旧版 McPing ping 测试。v的复杂预发布版本(prerelease)用例。Original summary in English
Summary by Sourcery
Align tests with updated networking, logging, and semantic versioning APIs and add coverage for new SemVer scenarios.
Bug Fixes:
Tests: