From 774925078a7af5342186960eddb0c60ea1000cdd Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 23 Sep 2024 11:17:58 +0200 Subject: [PATCH] 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. --- connpool.go | 5 ++--- connpool_test.go | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/connpool.go b/connpool.go index f774806..d875793 100644 --- a/connpool.go +++ b/connpool.go @@ -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. diff --git a/connpool_test.go b/connpool_test.go index 536dffc..4baf084 100644 --- a/connpool_test.go +++ b/connpool_test.go @@ -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.") }