Fix ConnPool.Deallocate

alloc-reduction
Jack Christensen 2016-04-30 12:22:26 -05:00
parent 88acc7e19f
commit acd9c01bd6
3 changed files with 37 additions and 0 deletions

View File

@ -1,3 +1,9 @@
# Unreleased
## Fixes
* Fix *ConnPool.Deallocate() not deleting prepared statement from map
# 2.8.1 (March 24, 2016)
## Features

View File

@ -366,6 +366,7 @@ func (p *ConnPool) Deallocate(name string) (err error) {
}
p.invalidateAcquired()
delete(p.preparedStatements, name)
return nil
}

View File

@ -733,6 +733,36 @@ func TestConnPoolPrepare(t *testing.T) {
}
}
func TestConnPoolPrepareDeallocatePrepare(t *testing.T) {
t.Parallel()
pool := createConnPool(t, 2)
defer pool.Close()
_, err := pool.Prepare("test", "select $1::varchar")
if err != nil {
t.Fatalf("Unable to prepare statement: %v", err)
}
err = pool.Deallocate("test")
if err != nil {
t.Fatalf("Unable to deallocate statement: %v", err)
}
_, err = pool.Prepare("test", "select $1::varchar")
if err != nil {
t.Fatalf("Unable to prepare statement: %v", err)
}
var s string
err = pool.QueryRow("test", "hello").Scan(&s)
if err != nil {
t.Fatalf("Executing prepared statement failed: %v", err)
}
if s != "hello" {
t.Errorf("Prepared statement did not return expected value: %v", s)
}
}
func TestConnPoolPrepareWhenConnIsAlreadyAcquired(t *testing.T) {
t.Parallel()