runChannelTestTask runs one synchronous channel test cycle for the system task runner (both the scheduled job and the manual "test all channels" trigger go through here). It honors ctx cancellation so a runner that loses its lease stops promptly. mode selects the channel set: an empty mode falls bac
(ctx context.Context, mode string, notify bool, report func(processed, total int))
| 995 | // is set the root user is notified on completion. Cross-instance execution is |
| 996 | // guarded by the system task per-type lock, so no process-local guard is needed. |
| 997 | func runChannelTestTask(ctx context.Context, mode string, notify bool, report func(processed, total int)) (channelTestSummary, error) { |
| 998 | testUserID, err := resolveChannelTestUserID(nil) |
| 999 | if err != nil { |
| 1000 | return channelTestSummary{}, err |
| 1001 | } |
| 1002 | channels, err := model.GetAllChannels(0, 0, true, false) |
| 1003 | if err != nil { |
| 1004 | return channelTestSummary{}, err |
| 1005 | } |
| 1006 | if strings.TrimSpace(mode) == "" { |
| 1007 | mode = operation_setting.GetMonitorSetting().ChannelTestMode |
| 1008 | } |
| 1009 | selected := selectChannelsForAutomaticTest(channels, mode) |
| 1010 | allowDisable := mode != operation_setting.ChannelTestModePassiveRecovery |
| 1011 | summary := performChannelTests(ctx, selected, testUserID, allowDisable, report) |
| 1012 | if notify && (ctx == nil || ctx.Err() == nil) { |
| 1013 | service.NotifyRootUser(dto.NotifyTypeChannelTest, "通道测试完成", "所有通道测试已完成") |
| 1014 | } |
| 1015 | return summary, nil |
| 1016 | } |
| 1017 | |
| 1018 | func selectChannelsForAutomaticTest(channels []*model.Channel, mode string) []*model.Channel { |
| 1019 | selected := make([]*model.Channel, 0, len(channels)) |
no test coverage detected