Improve error handling in connection pool tests

Add error checks to Close() calls in connpool_test.go to ensure connection closures are handled properly, with descriptive error messages. Update comment in connpool.go to improve clarity on the source of code inspiration.
This commit is contained in:
Winni Neessen 2024-09-23 11:17:58 +02:00
parent f1188bdad7
commit 774925078a
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 8 additions and 5 deletions

View file

@ -12,9 +12,8 @@ import (
"sync"
)
// Parts of the connection pool code is forked from https://github.com/fatih/pool/
// Thanks to Fatih Arslan and the project contributors for providing this great
// concurrency template.
// Parts of the connection pool code is forked/took inspiration from https://github.com/fatih/pool/
// Thanks to Fatih Arslan and the project contributors for providing this great concurrency template.
var (
// ErrClosed is returned when an operation is attempted on a closed connection pool.

View file

@ -175,7 +175,9 @@ func TestPoolConn_Close(t *testing.T) {
conns[i] = conn
}
for _, conn := range conns {
conn.Close()
if err = conn.Close(); err != nil {
t.Errorf("failed to close connection: %s", err)
}
}
if p.Size() != 30 {
@ -191,7 +193,9 @@ func TestPoolConn_Close(t *testing.T) {
}
p.Close()
conn.Close()
if err = conn.Close(); err != nil {
t.Errorf("failed to close connection: %s", err)
}
if p.Size() != 0 {
t.Errorf("closed pool shouldn't allow to put connections.")
}