v0.4.0:窗口调度/限流分类/可观测性,抢购改每账号独立循环,移除 CLI 只保留 GUI
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package huya
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"huya-go/internal/wup"
|
||||
)
|
||||
|
||||
// TestProtocolResponseErrorCarriesDiagnostics 验证「缺少 tRsp/tResp」错误会带上 WUP 诊断信息,
|
||||
// 并且可以用 errors.Is 判定——上层据此把它单独归类(sniper.CategoryProtocol),
|
||||
// 而不是混进普通失败里(2026-10-16 pc-3 同一账号连续 13 次命中该错误)。
|
||||
func TestProtocolResponseErrorCarriesDiagnostics(t *testing.T) {
|
||||
resp := &wup.Response{
|
||||
Message: -1,
|
||||
Status: map[string]string{"STATUS_RESULT_CODE": "-1"},
|
||||
NewData: map[string][]byte{"tErr": {0x0c}},
|
||||
}
|
||||
err := protocolResponseError(ServantWebActUI, FuncExchangePrize, resp)
|
||||
if !errors.Is(err, ErrProtocolResponse) {
|
||||
t.Fatalf("错误应可用 errors.Is(ErrProtocolResponse) 判定: %v", err)
|
||||
}
|
||||
text := err.Error()
|
||||
for _, want := range []string{
|
||||
"响应缺少 tRsp/tResp",
|
||||
"iRet=-1",
|
||||
"STATUS_RESULT_CODE=-1",
|
||||
"keys={tErr(1B)}",
|
||||
} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatalf("错误信息 %q 缺少 %q", text, want)
|
||||
}
|
||||
}
|
||||
|
||||
empty := protocolResponseError(ServantWebActUI, FuncExchangePrize, nil)
|
||||
if !errors.Is(empty, ErrProtocolResponse) || !strings.Contains(empty.Error(), "响应缺少 tRsp/tResp") {
|
||||
t.Fatalf("空响应错误=%v", empty)
|
||||
}
|
||||
if errors.Is(errors.New("timeout"), ErrProtocolResponse) {
|
||||
t.Fatal("普通错误不该被判定为协议错误")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user