[ISSUE #8262] [Enhancement] Add tests and harden UtilAll.isItTimeToDo#10409
[ISSUE #8262] [Enhancement] Add tests and harden UtilAll.isItTimeToDo#10409ChaoXoX wants to merge 2 commits into
Conversation
RongtongJin
left a comment
There was a problem hiding this comment.
Thanks for the patch. I left two review comments around the behavior change and test stability.
| if (hour == nowHour) { | ||
| return true; | ||
| } | ||
| } catch (NumberFormatException ignored) { |
There was a problem hiding this comment.
Could we avoid silently ignoring invalid when tokens here, or at least log a warning when a token cannot be parsed or is outside the 0-23 range? This helper is used by scheduled maintenance paths such as commitlog cleanup and topic queue mapping cleanup. If deleteWhen or a similar schedule is misconfigured, returning false forever would silently disable the task and make the operator miss the configuration problem. The previous behavior failed loudly; changing that to silent ignore seems risky without some visibility.
| assertTrue(UtilAll.isItTimeToDo("foo; " + currentHour + " ; 25")); | ||
| assertTrue(UtilAll.isItTimeToDo(" " + currentHour + " ")); | ||
|
|
||
| assertFalse(UtilAll.isItTimeToDo(null)); |
There was a problem hiding this comment.
This test depends on the hour read here matching the hour read inside UtilAll.isItTimeToDo. It can theoretically become flaky if the test crosses an hour boundary between the two calls. Could we make the positive case independent of wall-clock timing, for example by passing all valid hours (0;1;...;23) and asserting it returns true, while keeping the invalid-token cases separate?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #10409 +/- ##
=============================================
- Coverage 48.99% 47.95% -1.05%
+ Complexity 13459 13282 -177
=============================================
Files 1375 1377 +2
Lines 100394 100623 +229
Branches 12964 12994 +30
=============================================
- Hits 49188 48251 -937
- Misses 45217 46432 +1215
+ Partials 5989 5940 -49 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
oss-sentinel-ai
left a comment
There was a problem hiding this comment.
Review: Approved ✅
PR: #10409 — [Enhancement] Add tests and harden UtilAll.isItTimeToDo
Type: Enhancement + Test coverage (12 files, +49/-17)
Code Analysis
UtilAll.isItTimeToDo hardening:
- ✅ Null/blank guard at method entry — prevents NPE
- ✅ Try-catch around
Integer.parseInt— gracefully handles non-numeric tokens instead of throwingNumberFormatException - ✅ Hour range validation (0-23) — skips out-of-range values
- ✅
Calendar.HOUR_OF_DAYcomputed once — minor efficiency improvement
Test coverage:
- ✅ Current hour match (positive case)
- ✅ Mixed input with invalid tokens (
foo; <hour> ; 25) - ✅ Whitespace handling
- ✅ Null, empty, blank, non-numeric, out-of-range (negative cases)
Documentation changes:
- Minor doc file renames and link fixes — unrelated but harmless
Verdict
Clean, well-scoped enhancement that improves robustness of scheduled task timing logic. Test coverage is comprehensive. No concerns.
🤖 Automated review by oss-sentinel-ai
Review by github-manager-botSummaryHarden Findings
Suggestions
Automated review by github-manager-bot |
Before Creating the Enhancement Request
I have confirmed that this should be classified as an enhancement rather than a bug/feature.
Summary
为 UtilAll.isItTimeToDo 增加边界输入的容错处理,并补充对应单测,提高 common 模块覆盖率。
Motivation
当前方法对 null、空白和非法数字输入会抛 NumberFormatException,容易影响定时任务判断流程。补充容错逻辑与单测能提高健壮性并提升覆盖率。
Describe the Solution You'd Like
UtilAll.isItTimeToDo 对 null/空白/非法 token 安全忽略,跳过越界小时值。
新增单测覆盖:
当前小时命中
含非法 token 的混合输入
null/空串/空白/非法数字/越界小时
Describe Alternatives You've Considered
暂无
Additional Context
关联 #8262(提升项目整体测试覆盖率)。