Skip to content

Commit 3296360

Browse files
committed
api: add connection_pool.ErrExists
ConnectionPool.Add() returns the error if an endpoint exists in a connection pool.
1 parent c810cb3 commit 3296360

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

connection_pool/connection_pool.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var (
3030
ErrNoRwInstance = errors.New("can't find rw instance in pool")
3131
ErrNoRoInstance = errors.New("can't find ro instance in pool")
3232
ErrNoHealthyInstance = errors.New("can't find healthy instance in pool")
33+
ErrExists = errors.New("endpoint exists")
3334
ErrClosed = errors.New("pool is closed")
3435
)
3536

@@ -233,7 +234,7 @@ func (pool *ConnectionPool) Add(addr string) error {
233234
}
234235
if _, ok := pool.addrs[addr]; ok {
235236
pool.addrsMutex.Unlock()
236-
return errors.New("endpoint exist")
237+
return ErrExists
237238
}
238239
pool.addrs[addr] = e
239240
pool.addrsMutex.Unlock()

connection_pool/connection_pool_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestAdd_exist(t *testing.T) {
282282
defer connPool.Close()
283283

284284
err = connPool.Add(servers[0])
285-
require.ErrorContains(t, err, "endpoint exist")
285+
require.Equal(t, connection_pool.ErrExists, err)
286286

287287
args := test_helpers.CheckStatusesArgs{
288288
ConnPool: connPool,

0 commit comments

Comments
 (0)