You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.0 KiB
29 lines
1.0 KiB
package translate
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
// 用线上真实的报错文本验证限流识别:识别不出来就不会重试,一次限流就把整篇译文废掉。
|
|
func TestIsThrottling(t *testing.T) {
|
|
prodErr := errors.New(`translate request: SDK.ServerError
|
|
ErrorCode: Throttling.User
|
|
Recommend: https://api.aliyun.com/troubleshoot?q=Throttling.User&product=alimt
|
|
RequestId: 019F3BB4-F581-5AEE-80BE-74DB1FB673E1
|
|
Message: Request was denied due to user flow control.`)
|
|
if !isThrottling(prodErr) {
|
|
t.Fatal("线上 Throttling.User 报错未被识别为限流,重试不会触发")
|
|
}
|
|
|
|
if !isThrottling(errors.New("Request was denied due to user flow control.")) {
|
|
t.Error("flow control 文案应识别为限流")
|
|
}
|
|
// 非限流错误不应重试(例如参数错误),否则白白拖慢失败路径
|
|
if isThrottling(errors.New("translate failed: code=10004 msg=empty source text")) {
|
|
t.Error("参数错误被误判为限流,会导致无谓重试")
|
|
}
|
|
if isThrottling(nil) {
|
|
t.Error("nil 不应判为限流")
|
|
}
|
|
}
|
|
|