Skip to content

Commit

Permalink
Merge pull request #3 from randall-fulton/fix-unavailable-connections…
Browse files Browse the repository at this point in the history
…-not-refreshed

Ensure closed connections are replaced
  • Loading branch information
buraksezer authored Feb 23, 2022
2 parents b8141c7 + 430b46c commit 590c63f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,22 @@ func TestPool_Get1(t *testing.T) {
}
wg.Wait()
}

func TestPool_ClosedConnectionsReplaced(t *testing.T) {
p, _ := NewChannelPool(1, 1, factory)
defer p.Close()

conn, _ := p.Get(context.Background())

conn.(*PoolConn).MarkUnusable()
conn.Close()

ctx, _ := context.WithTimeout(context.Background(), 10*time.Millisecond)
conn, err := p.Get(ctx)
if err != nil {
t.Errorf("expected nil, got: %v", err)
}
if conn == nil {
t.Errorf("expected non-nil conn")
}
}
1 change: 1 addition & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (p *PoolConn) Close() error {

if p.unusable {
if p.Conn != nil {
<-p.c.semaphore
return p.Conn.Close()
}
return nil
Expand Down

0 comments on commit 590c63f

Please sign in to comment.