feat(sdk): 心跳失败指数退避(1m..15m)
- heartbeatLoop 失败后指数退避、成功后恢复 normal interval - 新增退避计算测试
This commit is contained in:
3 files changed
+90
-9
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBackoffDelay_ExponentialAndCap(t *testing.T) {
|
||||
c := &Client{}
|
||||
cases := []struct {
|
||||
failures int
|
||||
want time.Duration
|
||||
}{
|
||||
{1, time.Minute},
|
||||
{2, 2 * time.Minute},
|
||||
{3, 4 * time.Minute},
|
||||
{4, 8 * time.Minute},
|
||||
{5, 15 * time.Minute}, // 16m 封顶 15m
|
||||
{10, 15 * time.Minute},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := c.backoffDelay(tc.failures); got != tc.want {
|
||||
t.Errorf("failures=%d got=%s want=%s", tc.failures, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeartbeatDelay_NormalInterval(t *testing.T) {
|
||||
c := &Client{}
|
||||
c.heartbeatEvery = 900
|
||||
if got := c.heartbeatDelay(0); got != 15*time.Minute {
|
||||
t.Errorf("正常间隔: %s", got)
|
||||
}
|
||||
if got := c.heartbeatDelay(1); got != time.Minute {
|
||||
t.Errorf("首次失败退避: %s", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user