Commit ca3ed9f3 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

database/sql: add a disabled broken test

Update #6081

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/12810043
parent c7d352c9
...@@ -1372,6 +1372,8 @@ func (rs *Rows) Scan(dest ...interface{}) error { ...@@ -1372,6 +1372,8 @@ func (rs *Rows) Scan(dest ...interface{}) error {
return nil return nil
} }
var rowsCloseHook func(*Rows, *error)
// Close closes the Rows, preventing further enumeration. If the // Close closes the Rows, preventing further enumeration. If the
// end is encountered, the Rows are closed automatically. Close // end is encountered, the Rows are closed automatically. Close
// is idempotent. // is idempotent.
...@@ -1381,6 +1383,9 @@ func (rs *Rows) Close() error { ...@@ -1381,6 +1383,9 @@ func (rs *Rows) Close() error {
} }
rs.closed = true rs.closed = true
err := rs.rowsi.Close() err := rs.rowsi.Close()
if fn := rowsCloseHook; fn != nil {
fn(rs, &err)
}
if rs.closeStmt != nil { if rs.closeStmt != nil {
rs.closeStmt.Close() rs.closeStmt.Close()
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package sql package sql
import ( import (
"database/sql/driver"
"fmt" "fmt"
"reflect" "reflect"
"runtime" "runtime"
...@@ -1110,6 +1111,52 @@ func manyConcurrentQueries(t testOrBench) { ...@@ -1110,6 +1111,52 @@ func manyConcurrentQueries(t testOrBench) {
wg.Wait() wg.Wait()
} }
func TestIssue6081(t *testing.T) {
t.Skip("known broken test")
db := newTestDB(t, "people")
defer closeDB(t, db)
drv := db.driver.(*fakeDriver)
drv.mu.Lock()
opens0 := drv.openCount
closes0 := drv.closeCount
drv.mu.Unlock()
stmt, err := db.Prepare("SELECT|people|name|")
if err != nil {
t.Fatal(err)
}
rowsCloseHook = func(rows *Rows, err *error) {
*err = driver.ErrBadConn
}
defer func() { rowsCloseHook = nil }()
for i := 0; i < 10; i++ {
rows, err := stmt.Query()
if err != nil {
t.Fatal(err)
}
rows.Close()
}
if n := len(stmt.css); n > 1 {
t.Errorf("len(css slice) = %d; want <= 1", n)
}
stmt.Close()
if n := len(stmt.css); n != 0 {
t.Errorf("len(css slice) after Close = %d; want 0", n)
}
drv.mu.Lock()
opens := drv.openCount - opens0
closes := drv.closeCount - closes0
drv.mu.Unlock()
if opens < 9 {
t.Errorf("opens = %d; want >= 9", opens)
}
if closes < 9 {
t.Errorf("closes = %d; want >= 9", closes)
}
}
func TestConcurrency(t *testing.T) { func TestConcurrency(t *testing.T) {
manyConcurrentQueries(t) manyConcurrentQueries(t)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment