优化和平小店抢购重试策略

This commit is contained in:
yml2213
2026-08-09 14:48:20 +08:00
parent 87cb1dc3f0
commit 754e3f1ca8
2 changed files with 72 additions and 15 deletions
+24
View File
@@ -121,6 +121,30 @@ func TestClassifyXiaodianRetryStopOwnedItem(t *testing.T) {
}
}
func TestClassifyXiaodianRetryStop(t *testing.T) {
cases := []struct {
message string
account bool
product bool
reason string
}{
{"不好意思,您的余额不足~", true, false, "点券余额不足"},
{"点券不足,请充值后重试", true, false, "点券余额不足"},
{"未绑定账号", true, false, "账号未绑定角色"},
{"商品不存在", false, true, "商品不可兑换"},
{"已达限量", false, false, ""},
{"已达本次活动兑换上限", false, false, ""},
{"库存不足", false, false, ""},
}
for _, tc := range cases {
account, product, reason := classifyXiaodianRetryStop(tc.message)
if account != tc.account || product != tc.product || reason != tc.reason {
t.Errorf("classifyXiaodianRetryStop(%q) = (%v,%v,%q), want (%v,%v,%q)",
tc.message, account, product, reason, tc.account, tc.product, tc.reason)
}
}
}
func TestFilterCooldownAttempts(t *testing.T) {
attempts := makeAttempts("a", "b", "c")
now := time.Now()