refactor: phase 3 integrated new dialing pattern into pool

This commit is contained in:
Jay
2026-06-06 18:32:52 -04:00
parent a46e9f7ad8
commit 1977fb385a
5 changed files with 85 additions and 75 deletions
+10 -2
View File
@@ -85,14 +85,22 @@ func DialWithRetry(
for {
if logger != nil {
logger.Debug("dialing", "attempt", mgr.RetryCount()+1)
if mgr == nil {
logger.Debug("dialing")
} else {
logger.Debug("dialing", "attempt", mgr.RetryCount()+1)
}
}
// dial
socket, err := dialFn(ctx)
if err == nil {
if logger != nil {
logger.Debug("dial successful", "attempt", mgr.RetryCount()+1)
if mgr == nil {
logger.Debug("dial successful")
} else {
logger.Debug("dial successful", "attempt", mgr.RetryCount()+1)
}
}
return socket, nil
}
+11 -1
View File
@@ -7,6 +7,7 @@ import (
"git.wisehodl.dev/jay/go-honeybee/honeybeetest"
"git.wisehodl.dev/jay/go-honeybee/types"
"github.com/stretchr/testify/assert"
"sync"
"sync/atomic"
"testing"
"time"
@@ -252,8 +253,13 @@ func TestDialWithRetry_DialErrors(t *testing.T) {
}
}
var mu sync.Mutex
var gotErrors []error
onError := func(err error) { gotErrors = append(gotErrors, err) }
onError := func(err error) {
mu.Lock()
defer mu.Unlock()
gotErrors = append(gotErrors, err)
}
retryCfg, _ := NewRetryConfig(
WithMaxRetries(3),
@@ -269,9 +275,13 @@ func TestDialWithRetry_DialErrors(t *testing.T) {
}()
honeybeetest.Eventually(t, func() bool {
mu.Lock()
defer mu.Unlock()
return len(gotErrors) == 2
}, "expected errors")
mu.Lock()
defer mu.Unlock()
assert.Equal(t, dialErr1, gotErrors[0])
assert.Equal(t, dialErr2, gotErrors[1])
})