mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
* add dial retry backoff function. * add readme * add backoff to wordlist * add logical consistency check * fix(cluster): propagate DialerRetryBackoff to per-node clients ClusterOptions.clientOptions() was not propagating DialerRetryBackoff, causing the backoff function to be silently ignored when set on a cluster client. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Nedyalko Dyakov <[email protected]> Co-authored-by: Claude Sonnet 4.6 <[email protected]>
30 lines
724 B
Go
30 lines
724 B
Go
package pool
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDialRetryBackoff_ConstantByDefault_ExponentialWhenMaxSet(t *testing.T) {
|
|
p := &ConnPool{cfg: &Options{DialerRetryTimeout: 10 * time.Millisecond}}
|
|
|
|
// default constant when max not set
|
|
for i := 0; i < 5; i++ {
|
|
if got := p.dialRetryBackoff(i); got != 10*time.Millisecond {
|
|
t.Fatalf("constant: attempt=%d got %v", i, got)
|
|
}
|
|
}
|
|
|
|
// custom function
|
|
p.cfg.DialerRetryBackoff = func(attempt int) time.Duration {
|
|
return time.Duration(attempt+1) * time.Millisecond
|
|
}
|
|
for i := 0; i < 5; i++ {
|
|
got := p.dialRetryBackoff(i)
|
|
want := time.Duration(i+1) * time.Millisecond
|
|
if got != want {
|
|
t.Fatalf("custom: attempt=%d got %v, want %v", i, got, want)
|
|
}
|
|
}
|
|
}
|