51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
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 }
|