Files
sub2api/backend/internal/service/channel_monitor_probe_retirement_test.go
T
IanShaw027 825f9c78d5 fix(channel-monitor-v2): default mode v1 and gentle adaptive backfill
Default channel_monitor_mode to v1 (opt-in V2) so upgrades keep active
probes; existing explicit v2 rows are left alone via ON CONFLICT DO NOTHING
plus migration checksum compatibility for already-applied 195.

V2 first-enable backfill no longer compresses ticks to 5s or uses 24h
chunks. Each tick does recent overlap plus at most one historical chunk
with depth-based ceilings (2h/4h/6h), adaptive grow/shrink, and failure
backoff. Error request_id dedup is bounded by a 90-minute lookback so
ops_error_logs is not scanned for full history.

Also align hide_throughput parse default with privacy-preserving public
runtime (missing key → true).
2026-08-08 13:59:11 +08:00

64 lines
2.2 KiB
Go

//go:build unit
package service
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
type channelMonitorRuntimeStub struct {
rt ChannelMonitorRuntime
}
func (s channelMonitorRuntimeStub) GetChannelMonitorRuntime(context.Context) ChannelMonitorRuntime {
return s.rt
}
func TestRunCheck_ModeV2NeverProbes(t *testing.T) {
svc := NewChannelMonitorService(nil, nil)
svc.SetRuntimeReader(channelMonitorRuntimeStub{rt: ChannelMonitorRuntime{
Enabled: true,
Mode: ChannelMonitorModeV2,
}})
results, err := svc.RunCheck(context.Background(), 1)
require.ErrorIs(t, err, ErrChannelMonitorActiveProbesRetired)
require.Nil(t, results)
}
func TestRunCheck_DisabledReturnsDisabled(t *testing.T) {
svc := NewChannelMonitorService(nil, nil)
svc.SetRuntimeReader(channelMonitorRuntimeStub{rt: ChannelMonitorRuntime{
Enabled: false,
Mode: ChannelMonitorModeV1,
}})
_, err := svc.RunCheck(context.Background(), 1)
require.ErrorIs(t, err, ErrChannelMonitorDisabled)
}
func TestRunCheck_NilRuntimeReaderFailsClosedAsV2(t *testing.T) {
svc := NewChannelMonitorService(nil, nil)
// No SetRuntimeReader → probeRuntime defaults to mode=v2 (retired).
_, err := svc.RunCheck(context.Background(), 1)
require.ErrorIs(t, err, ErrChannelMonitorActiveProbesRetired)
}
func TestNormalizeChannelMonitorMode(t *testing.T) {
require.Equal(t, ChannelMonitorModeV1, normalizeChannelMonitorMode(""))
require.Equal(t, ChannelMonitorModeV1, normalizeChannelMonitorMode("v1"))
require.Equal(t, ChannelMonitorModeV2, normalizeChannelMonitorMode("v2"))
require.Equal(t, ChannelMonitorModeV1, normalizeChannelMonitorMode("invalid"))
require.Equal(t, ChannelMonitorModeV1, normalizeChannelMonitorMode(" V1 "))
}
func TestChannelMonitorRuntimeActiveProbesAllowed(t *testing.T) {
require.False(t, (ChannelMonitorRuntime{Enabled: false, Mode: ChannelMonitorModeV1}).ActiveProbesAllowed())
require.True(t, (ChannelMonitorRuntime{Enabled: true, Mode: ChannelMonitorModeV1}).ActiveProbesAllowed())
require.False(t, (ChannelMonitorRuntime{Enabled: true, Mode: ChannelMonitorModeV2}).ActiveProbesAllowed())
require.True(t, (ChannelMonitorRuntime{Enabled: true, Mode: ChannelMonitorModeV2}).PassiveAggregationAllowed())
}