-
Notifications
You must be signed in to change notification settings - Fork 2
test(core): Add oshi 测试case #2134
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
Close #1215 Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com>
|
Thank you for following naming conventions! 😻 |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Reviewer's GuideThis pull request introduces a comprehensive suite of JUnit 5 tests for the File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Their most recently public accepted PR is: #2130 |
Close #1215 Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com>
|
""" Walkthrough本次变更主要扩展和重构了 Changes
Sequence Diagram(s)sequenceDiagram
participant TestRunner
participant OshiTest
participant OshiUtil
participant OSHI
TestRunner->>OshiTest: 执行各类测试方法
OshiTest->>OSHI: 获取硬件/系统信息
OshiTest-->>TestRunner: 打印/输出结果
TestRunner->>OshiUtilTest: 执行工具类测试方法
OshiUtilTest->>OshiUtil: 调用工具方法(如 getCpuInfo, getMemory)
OshiUtil->>OSHI: 获取底层系统信息
OshiUtil-->>OshiUtilTest: 返回信息
OshiUtilTest-->>TestRunner: 断言/输出结果
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used🪛 actionlint (1.7.4).github/workflows/check-aliyun-maven.yml241-241: could not parse as YAML: yaml: line 241: did not find expected key (syntax-check) 🪛 YAMLlint (1.35.1).github/workflows/check-aliyun-maven.yml[error] 242-242: syntax error: expected , but found '' (syntax) ⏰ Context from checks skipped due to timeout of 90000ms (8)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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 @unknowIfGuestInDream - I've reviewed your changes - here's some feedback:
- The copyright year appears to have been incorrectly updated to 2025.
- Consider adding assertions to the new test methods to verify the expected behavior or data format, rather than just printing to the console.
- The entire test class is marked as
@Disabled; clarify if these tests are intended to be run automatically or remove the annotation if they should be active.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟡 Testing: 5 issues found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Actionable comments posted: 3
🧹 Nitpick comments (6)
core/src/test/java/com/tlcsdm/core/oshi/OshiUtilTest.java (1)
64-67: 仅打印 CPU 使用率,建议增加数值区间断言如果希望保留输出,可同时校验:
double used = OshiUtil.getCpuInfo().getUsed(); System.out.println("CPU Used: " + used); Assertions.assertTrue(used >= 0 && used <= 100, "CPU 使用率应在 0~100 之间");core/src/test/java/com/tlcsdm/core/oshi/OshiTest.java (5)
55-58: 大体测试均被 @disabled 且只打印,无断言本类更多像演示/调试脚本而非单元测试,会导致覆盖率统计失真,也无法在 CI 中捕获异常。
可考虑:
- 将关键逻辑验证迁移到
OshiUtilTest并保留少量集成测试;- 对仍需手动检查的用例保留
@Disabled("manual");- 或使用 JUnit 5 的
assumeTrue在条件不满足时跳过。
121-129: phyMemory 用例缺少断言,仅输出信息建议至少校验物理内存条数量或容量大于 0,示例:
Assertions.assertFalse(pmList.isEmpty(), "未检测到物理内存"); Assertions.assertTrue(OshiUtil.getMemory().getTotal() > 0, "总内存应大于 0");
148-153: cpu() 测试同样缺少有效断言可复用
CpuInfo中的数值进行区间校验,避免仅打印:见OshiUtilTest建议。
172-188: 遍历所有进程并大量打印,运行成本高
getProcesses(null, null, 0)可能返回上千进程,输出巨大且拖慢测试。若确为调试用途,建议:
- 限制数量,如
getProcesses(5, OperatingSystem.ProcessSort.CPU);- 或移至单独的性能/诊断工具类,不放在常规测试套件中。
238-252: getIPAddressesString 可用String.join简化-private String getIPAddressesString(String[] ipAddressArr) { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (String ipAddress : ipAddressArr) { - if (first) { - first = false; - } else { - sb.append("; "); - } - sb.append(ipAddress); - } - return sb.toString(); -} +private String getIPAddressesString(String[] ipAddressArr) { + return String.join("; ", ipAddressArr); +}更简洁、无需显式循环。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
core/src/test/java/com/tlcsdm/core/oshi/OshiTest.java(2 hunks)core/src/test/java/com/tlcsdm/core/oshi/OshiUtilTest.java(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
core/src/test/java/com/tlcsdm/core/oshi/OshiUtilTest.java (1)
core/src/main/java/com/tlcsdm/core/oshi/OshiUtil.java (1)
OshiUtil(53-176)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: build (21, ubuntu-latest, false)
- GitHub Check: build (17, ubuntu-latest, false)
- GitHub Check: qodana
- GitHub Check: build (21, windows-latest, false)
- GitHub Check: build (17, macos-latest, false)
- GitHub Check: build (21, macos-latest, false)
- GitHub Check: build (17, windows-latest, false)
- GitHub Check: Summary
🔇 Additional comments (1)
core/src/test/java/com/tlcsdm/core/oshi/OshiUtilTest.java (1)
38-40: 谨慎使用类级别 @disabled,可能导致 CI 完全跳过新用例整个测试类被
@Disabled标记,CI / 构建流水线将不会执行任何断言,从而无法及时发现回归问题。
若仅是环境限制(如需物理硬件),建议:
- 为每个测试单独加
@Disabled("原因"),并留下 TODO,方便后期定位与启用;- 或使用
@EnabledIfEnvironmentVariable等条件化注解,只在满足条件时跳过。
请确认这是团队的预期行为。
Qodana Community for JVMIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
Close #1215 Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com>
|



Close #1215
Fixes #
Proposed Changes
Readiness Checklist
Author/Contributor
Reviewing Maintainer
enhancement,bug,documentationordependenciesSummary by Sourcery
Enhance Oshi test coverage by adding comprehensive system information tests across various hardware and software domains
Enhancements:
Tests:
Chores:
Summary by CodeRabbit