修复: 用户维度限速在过期节点组分支生效 + 统一 speed_limit 单位为 Mbps
- getServerUserListLogic.getExpiredUsers 之前完全忽略 user_subscribe.speed_limit, 现在带出用户级覆盖并与过期节点组 speed_limit 取更严(mergeSpeedLimit:0 视为无限制) - node_group.SpeedLimit 注释从 "KB/s" 修正为 "Mbps"(旧注释是笔误,实际下发节点的 ServerUser.SpeedLimit 字段语义就是 Mbps,节点端 ppanel-node 按 *1e6/8 换算为 Byte/s) - apis/node/node.api 给 ServerUser.SpeedLimit 加 Mbps 单位注释 - 新增 TestMergeSpeedLimit 表驱动测试覆盖 8 种边界 主链路(活跃用户、套餐 traffic_limit 阶梯)行为不变,已在生产 (server_id=52) 验证 147 个限速用户下发正确,与 DB 完全对应。
This commit is contained in:
@@ -338,3 +338,32 @@ func httptestNewRequest() *http.Request {
|
||||
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/v1/server/user", nil)
|
||||
return req
|
||||
}
|
||||
|
||||
// TestMergeSpeedLimit 验证用户级 speed_limit 与过期节点组 speed_limit 合并规则:
|
||||
// 0 = 不限制 (loses),正值优先;都为正取较小者(更严格)。
|
||||
// 这是 user-dimension 限速在过期节点组分支下能生效的关键。
|
||||
func TestMergeSpeedLimit(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
a int64
|
||||
b int64
|
||||
want int64
|
||||
}{
|
||||
{"both zero stays zero", 0, 0, 0},
|
||||
{"a positive b zero takes a", 30, 0, 30},
|
||||
{"a zero b positive takes b", 0, 50, 50},
|
||||
{"a negative treated as zero takes b", -1, 50, 50},
|
||||
{"b negative treated as zero takes a", 50, -1, 50},
|
||||
{"both positive takes smaller (a<b)", 20, 50, 20},
|
||||
{"both positive takes smaller (b<a)", 80, 30, 30},
|
||||
{"equal positive returns same value", 25, 25, 25},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := mergeSpeedLimit(tc.a, tc.b); got != tc.want {
|
||||
t.Fatalf("mergeSpeedLimit(%d, %d) = %d, want %d", tc.a, tc.b, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user