Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controller/channel-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func AutomaticallyTestChannels() {
}
for {
frequency := operation_setting.GetMonitorSetting().AutoTestChannelMinutes
time.Sleep(time.Duration(frequency) * time.Minute)
time.Sleep(time.Duration(int(math.Round(frequency))) * time.Minute)
common.SysLog(fmt.Sprintf("automatically test channels with interval %d minutes", frequency))
Comment on lines +628 to 629

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.

common.SysLog("automatically testing all channels")
_ = testAllChannels(false)
Expand Down
6 changes: 3 additions & 3 deletions setting/operation_setting/monitor_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

type MonitorSetting struct {
AutoTestChannelEnabled bool `json:"auto_test_channel_enabled"`
AutoTestChannelMinutes int `json:"auto_test_channel_minutes"`
AutoTestChannelEnabled bool `json:"auto_test_channel_enabled"`
AutoTestChannelMinutes float64 `json:"auto_test_channel_minutes"`
}

// 默认配置
Expand All @@ -28,7 +28,7 @@ func GetMonitorSetting() *MonitorSetting {
frequency, err := strconv.Atoi(os.Getenv("CHANNEL_TEST_FREQUENCY"))
if err == nil && frequency > 0 {
monitorSetting.AutoTestChannelEnabled = true
monitorSetting.AutoTestChannelMinutes = frequency
monitorSetting.AutoTestChannelMinutes = float64(frequency)
}
}
return &monitorSetting
Expand Down