53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"chat-agent-system/internal/config"
|
|
)
|
|
|
|
// T20-B7 回归:drain 窗口与 AGENT_TIMEOUT 对齐。
|
|
func TestShutdownDrainTimeout_DefaultCapped35m(t *testing.T) {
|
|
cfg := &config.Config{AgentTimeout: 60 * time.Minute} // 超过上限 → 封顶 35m
|
|
got := shutdownDrainTimeout(cfg)
|
|
want := 35*time.Minute + 30*time.Second
|
|
if got != want {
|
|
t.Fatalf("expect cap %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestShutdownDrainTimeout_FollowsShortAgentTimeout(t *testing.T) {
|
|
cfg := &config.Config{AgentTimeout: 10 * time.Minute} // 短于上限 → 跟随 +30s
|
|
got := shutdownDrainTimeout(cfg)
|
|
want := 10*time.Minute + 30*time.Second
|
|
if got != want {
|
|
t.Fatalf("expect %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestShutdownDrainTimeout_EnvOverride(t *testing.T) {
|
|
t.Setenv("SHUTDOWN_DRAIN_TIMEOUT", "45s")
|
|
cfg := &config.Config{AgentTimeout: 30 * time.Minute}
|
|
if got := shutdownDrainTimeout(cfg); got != 45*time.Second {
|
|
t.Fatalf("env override expect 45s, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestShutdownDrainTimeout_InvalidEnvFallsBack(t *testing.T) {
|
|
t.Setenv("SHUTDOWN_DRAIN_TIMEOUT", "not-a-duration")
|
|
cfg := &config.Config{AgentTimeout: 30 * time.Minute}
|
|
want := 30*time.Minute + 30*time.Second
|
|
if got := shutdownDrainTimeout(cfg); got != want {
|
|
t.Fatalf("invalid env expect fallback %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestShutdownDrainTimeout_NilCfg(t *testing.T) {
|
|
got := shutdownDrainTimeout(nil)
|
|
want := 30*time.Minute + 30*time.Second
|
|
if got != want {
|
|
t.Fatalf("nil cfg expect default %s, got %s", want, got)
|
|
}
|
|
}
|