fix: 按 K-00 约定修复 Go SDK 断线重交与退避
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package nixmsg
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DisableJitterForTest 让退避/限速等待等于标称值,便于单测。
|
||||
func DisableJitterForTest(t testing.TB) {
|
||||
t.Helper()
|
||||
orig := backoffJitter
|
||||
backoffJitter = func(d time.Duration) time.Duration { return d }
|
||||
t.Cleanup(func() { backoffJitter = orig })
|
||||
}
|
||||
|
||||
func NominalDelayForTest(n int) time.Duration { return nominalDelay(n) }
|
||||
|
||||
func (b *reconnectBackoff) NextWaitNoJitterForTest() time.Duration {
|
||||
return b.nextWait(false)
|
||||
}
|
||||
|
||||
func (b *reconnectBackoff) SetOnlineAtForTest(t time.Time) {
|
||||
b.setOnlineAtForTest(t)
|
||||
}
|
||||
|
||||
func (c *Client) LastStopCodeForTest() string {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.lastStopCode
|
||||
}
|
||||
|
||||
func (c *Client) DedupHasForTest(key string) bool {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.store.Has(key)
|
||||
}
|
||||
|
||||
func (c *Client) DedupPutForTest(key string, st dedupState) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.store.Put(key, &dedupEntry{state: st})
|
||||
}
|
||||
|
||||
func (c *Client) DedupDeleteForTest(key string) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.store.Delete(key)
|
||||
}
|
||||
|
||||
func DefaultKeepAliveSecondsForTest() int { return DefaultKeepAliveSeconds }
|
||||
Reference in New Issue
Block a user