线上实测 delivered 约 9 万行/天且该表无下游读方(事实在 lucky_draw_records), 30 天窗口会让表膨胀到近 300 万行;7 天足够排障。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLoadDefaultsEnableOutboxRetention(t *testing.T) {
|
|
cfg, err := Load("")
|
|
if err != nil {
|
|
t.Fatalf("Load(empty) failed: %v", err)
|
|
}
|
|
retention := cfg.LuckyGiftWorker.Retention
|
|
if !retention.Enabled {
|
|
t.Fatal("retention should be enabled by default")
|
|
}
|
|
if retention.MaxAge != 7*24*time.Hour {
|
|
t.Fatalf("retention.MaxAge = %s, want 168h", retention.MaxAge)
|
|
}
|
|
if retention.ScanInterval != 5*time.Minute {
|
|
t.Fatalf("retention.ScanInterval = %s, want 5m", retention.ScanInterval)
|
|
}
|
|
if retention.BatchSize != 500 {
|
|
t.Fatalf("retention.BatchSize = %d, want 500", retention.BatchSize)
|
|
}
|
|
}
|
|
|
|
func TestLoadRejectsRetentionMaxAgeBelowSafetyFloor(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "config.yaml")
|
|
content := `
|
|
lucky_gift_worker:
|
|
retention:
|
|
enabled: true
|
|
max_age: 30s
|
|
`
|
|
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
|
|
t.Fatalf("write config: %v", err)
|
|
}
|
|
if _, err := Load(path); err == nil || !strings.Contains(err.Error(), "safety floor") {
|
|
t.Fatalf("Load should reject max_age below 24h, got err=%v", err)
|
|
}
|
|
}
|