fix: 优化腾讯云账单同步限频
- 全局限制腾讯云API调用频率为每秒4次以内 - 对RequestLimitExceeded增加指数退避重试 - 补充限频回归测试并更新账单同步支持说明
This commit is contained in:
1 parent
7bc416d22a
commit
3a3f77ea62
5 files changed
+95
-7
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package cloud
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestTencentRetryDelay 验证限频错误指数退避与最大重试次数。 // Logan.Li
|
||||
func TestTencentRetryDelay(t *testing.T) {
|
||||
rateLimitErr := &tencentAPIError{Code: "RequestLimitExceeded", Message: "frequency limit"}
|
||||
delay, retry := tencentRetryDelay(rateLimitErr, 0)
|
||||
if !retry || delay != 500*time.Millisecond {
|
||||
t.Fatalf("首次限频退避错误: retry=%v delay=%s", retry, delay)
|
||||
}
|
||||
|
||||
delay, retry = tencentRetryDelay(rateLimitErr, 2)
|
||||
if !retry || delay != 2*time.Second {
|
||||
t.Fatalf("第三次限频退避错误: retry=%v delay=%s", retry, delay)
|
||||
}
|
||||
|
||||
if _, retry = tencentRetryDelay(rateLimitErr, tencentMaxAttempts-1); retry {
|
||||
t.Fatal("达到最大次数后不应继续重试")
|
||||
}
|
||||
if _, retry = tencentRetryDelay(errors.New("鉴权失败"), 0); retry {
|
||||
t.Fatal("非限频错误不应重试")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user