Skip to content

fix: test channel frequency - #2119

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/testchannel
Oct 28, 2025
Merged

fix: test channel frequency#2119
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/testchannel

Conversation

@seefs001

@seefs001 seefs001 commented Oct 28, 2025

Copy link
Copy Markdown
Collaborator

fix #2115

Summary by CodeRabbit

  • Bug Fixes
    • Channel test intervals are now rounded to whole minute values for consistent timing behavior in monitoring operations.

@coderabbitai

coderabbitai Bot commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The PR modifies AutoTestChannelMinutes to support fractional minute values by changing its type from int to float64 in the monitor settings struct, while adding rounding logic in the channel test controller to convert the frequency to a whole-minute integer before applying it to the timer interval.

Changes

Cohort / File(s) Summary
Type Conversion
setting/operation_setting/monitor_setting.go
Changed AutoTestChannelMinutes field from int to float64 to support fractional minute intervals. Environment variable conversion and default initialization updated accordingly.
Controller Integration
controller/channel-test.go
Added int(math.Round(frequency)) conversion to round the float64 frequency value to the nearest integer before multiplying by time.Minute for the sleep interval.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify that the math.Round() operation correctly handles edge cases for frequencies near .5 boundaries
  • Confirm the type change from int to float64 doesn't cause unintended JSON marshaling/unmarshaling behavior
  • Ensure all usages of AutoTestChannelMinutes downstream account for the new float64 type

Possibly related PRs

Poem

🐰 From whole to fractioned minutes we go,
A float64 dance, then round down low,
The timer ticks true with whole seconds' flow,
Precision and grace in each timer's glow! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "fix: test channel frequency" is directly related to the changeset. The modifications address how test channel frequency is handled by converting the AutoTestChannelMinutes field from int to float64 in the MonitorSetting struct and rounding the frequency value in the controller before use. The title accurately captures the main objective—fixing the test channel frequency functionality—and would allow a teammate scanning the git history to understand the primary focus of these changes. While the title doesn't specify the technical implementation details (float64 conversion and rounding), it clearly and concisely identifies the area of change.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
setting/operation_setting/monitor_setting.go (1)

27-32: Environment variable parsing still uses integer conversion, preventing fractional values.

The code parses CHANNEL_TEST_FREQUENCY using strconv.Atoi, which only accepts integer values. This prevents users from specifying fractional minutes (e.g., "0.5" for 30 seconds) via the environment variable, undermining the purpose of changing AutoTestChannelMinutes to float64.

Apply this diff to support fractional values from the environment:

 func GetMonitorSetting() *MonitorSetting {
 	if os.Getenv("CHANNEL_TEST_FREQUENCY") != "" {
-		frequency, err := strconv.Atoi(os.Getenv("CHANNEL_TEST_FREQUENCY"))
+		frequency, err := strconv.ParseFloat(os.Getenv("CHANNEL_TEST_FREQUENCY"), 64)
 		if err == nil && frequency > 0 {
 			monitorSetting.AutoTestChannelEnabled = true
-			monitorSetting.AutoTestChannelMinutes = float64(frequency)
+			monitorSetting.AutoTestChannelMinutes = frequency
 		}
 	}
 	return &monitorSetting
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3ed6a6 and 1710615.

📒 Files selected for processing (2)
  • controller/channel-test.go (1 hunks)
  • setting/operation_setting/monitor_setting.go (2 hunks)

Comment on lines +628 to 629
time.Sleep(time.Duration(int(math.Round(frequency))) * time.Minute)
common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Rounding negates fractional minute support; fix format specifier mismatch.

The implementation has two issues:

  1. Line 628: Rounding frequency to an integer defeats the purpose of changing AutoTestChannelMinutes to float64. If the intent is to support fractional minutes (e.g., 0.5 minutes = 30 seconds), the rounding should be removed.

  2. Line 629: The format specifier %d expects an integer but frequency is float64, causing incorrect output or potential issues.

Apply this diff to properly support fractional minutes:

-			time.Sleep(time.Duration(int(math.Round(frequency))) * time.Minute)
-			common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))
+			time.Sleep(time.Duration(frequency * float64(time.Minute)))
+			common.SysLog(fmt.Sprintf("automatically test channels with interval %.2f minutes", frequency))

Alternatively, if only whole minutes are needed, keep AutoTestChannelMinutes as int rather than converting to float64.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
time.Sleep(time.Duration(int(math.Round(frequency))) * time.Minute)
common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))
time.Sleep(time.Duration(frequency * float64(time.Minute)))
common.SysLog(fmt.Sprintf("automatically test channels with interval %.2f minutes", frequency))
🤖 Prompt for AI Agents
controller/channel-test.go around lines 628-629: the code currently rounds the
float64 frequency and prints it with %d, which removes fractional-minute support
and mismatches the format specifier; remove the math.Round usage and compute a
time.Duration from the float64 minutes by multiplying frequency by
float64(time.Minute) then converting to time.Duration and call time.Sleep with
that duration, and update the log to use a float format (e.g. "%.2f" or "%f")
when printing frequency in minutes.

@Calcium-Ion
Calcium-Ion merged commit 158b46e into QuantumNous:main Oct 28, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

定时测试功能间隔时间无效

2 participants