Files
yml2213 d4ba9e7a56 全局重命名:kefu_sys / kefu-sys 改为 kefu_cloud / kefu-cloud
- Go module 与全部 import 路径
- 数据库默认库名、Docker 服务/卷命名与部署文档
2026-07-15 15:23:10 +08:00

50 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handler
import (
"testing"
"kefu-cloud/server/internal/model"
)
func TestPickLeastLoadedPrefersFewerSessions(t *testing.T) {
a := model.User{ID: 1}
b := model.User{ID: 2}
c := model.User{ID: 3}
candidates := []model.User{a, b, c}
counts := map[uint]int64{1: 3, 2: 1, 3: 1}
got := pickLeastLoadedAgent(candidates, counts)
if got == nil || got.ID != 2 {
t.Fatalf("期望 id=2(平局取更小 id),got=%v", got)
}
}
func TestPickRoundRobinAdvances(t *testing.T) {
candidates := []model.User{{ID: 10}, {ID: 20}, {ID: 30}}
last := uint(10)
got := pickRoundRobinAgent(candidates, &last)
if got == nil || got.ID != 20 {
t.Fatalf("期望下一位 20got=%v", got)
}
last = 30
got = pickRoundRobinAgent(candidates, &last)
if got == nil || got.ID != 10 {
t.Fatalf("期望绕回 10got=%v", got)
}
got = pickRoundRobinAgent(candidates, nil)
if got == nil || got.ID != 10 {
t.Fatalf("无游标时期望第一位 10got=%v", got)
}
}
func TestNormalizeAssignStrategy(t *testing.T) {
if normalizeAssignStrategy("round_robin") != assignStrategyRoundRobin {
t.Fatal("round_robin")
}
if normalizeAssignStrategy("") != assignStrategyLeastLoad {
t.Fatal("default least_load")
}
if normalizeAssignStrategy("unknown") != assignStrategyLeastLoad {
t.Fatal("unknown -> least_load")
}
}