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) } }