v0.4.0:窗口调度/限流分类/可观测性,抢购改每账号独立循环,移除 CLI 只保留 GUI

This commit is contained in:
yml2213
2026-10-16 18:14:30 +08:00
parent 29aed15e4e
commit 8b3b14654f
20 changed files with 2309 additions and 664 deletions
+54
View File
@@ -1,6 +1,7 @@
package wup_test
import (
"strings"
"testing"
"huya-go/internal/huya"
@@ -31,3 +32,56 @@ func TestWupEncodeDecodeHeader(t *testing.T) {
t.Fatal("missing tReq")
}
}
// TestResponseDiagnoseIncludesServerFields 验证诊断串会把 WUP 响应里的排障字段带出来。
//
// 2026-10-16 的复盘卡在「响应缺少 tRsp/tResp」只有一句文案:服务端回的 iRet、
// status、context 与数据体键名全被丢掉,同一账号连续 13 次命中也无法定性。
func TestResponseDiagnoseIncludesServerFields(t *testing.T) {
resp := &wup.Response{
Message: -1,
Servant: "webActUI",
Func: "scoreExchangePrize",
Status: map[string]string{"STATUS_RESULT_DESC": "风控拦截", "STATUS_RESULT_CODE": "-1"},
Context: map[string]string{"uid": "123"},
NewData: map[string][]byte{"tErr": {0x0c}},
Buffer: []byte{1, 2, 3},
}
got := resp.Diagnose()
for _, want := range []string{
"iRet=-1",
"servant=webActUI.scoreExchangePrize",
"STATUS_RESULT_CODE=-1",
"STATUS_RESULT_DESC=风控拦截",
"context={uid=123}",
"keys={tErr(1B)}",
"payload=3B",
} {
if !strings.Contains(got, want) {
t.Fatalf("Diagnose()=%q,缺少 %q", got, want)
}
}
if got := (*wup.Response)(nil).Diagnose(); got != "响应为空" {
t.Fatalf("空响应诊断=%q", got)
}
if got := (&wup.Response{}).Diagnose(); !strings.Contains(got, "iRet=0") || !strings.Contains(got, "keys=空") {
t.Fatalf("零值响应诊断=%q", got)
}
}
// TestHexHead 验证原始帧前缀输出的截断与边界。
func TestHexHead(t *testing.T) {
data := []byte{0x1f, 0x8b, 0x08, 0x00}
if got := wup.HexHead(data, 2); got != "1f8b" {
t.Fatalf("HexHead(2)=%q", got)
}
if got := wup.HexHead(data, 32); got != "1f8b0800" {
t.Fatalf("HexHead 越界应截断到实际长度: %q", got)
}
if got := wup.HexHead(nil, 8); got != "" {
t.Fatalf("空数据=%q", got)
}
if got := wup.HexHead(data, 0); got != "" {
t.Fatalf("长度为 0=%q", got)
}
}