mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Revert "database/sql: add driver.ResetSessioner and add pool support"
This reverts commit 2620ac3aea.
Reason for revert: broke all the builds.
Change-Id: I26fc09a13f5f80fa708de66c843442ff9d934694
Reviewed-on: https://go-review.googlesource.com/73050
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
8c58900aeb
commit
3b9d947b2f
4 changed files with 25 additions and 214 deletions
|
|
@ -60,12 +60,10 @@ const fakeDBName = "foo"
|
|||
var chrisBirthday = time.Unix(123456789, 0)
|
||||
|
||||
func newTestDB(t testing.TB, name string) *DB {
|
||||
return newTestDBConnector(t, &fakeConnector{name: fakeDBName}, name)
|
||||
}
|
||||
|
||||
func newTestDBConnector(t testing.TB, fc *fakeConnector, name string) *DB {
|
||||
fc.name = fakeDBName
|
||||
db := OpenDB(fc)
|
||||
db, err := Open("test", fakeDBName)
|
||||
if err != nil {
|
||||
t.Fatalf("Open: %v", err)
|
||||
}
|
||||
if _, err := db.Exec("WIPE"); err != nil {
|
||||
t.Fatalf("exec wipe: %v", err)
|
||||
}
|
||||
|
|
@ -587,46 +585,24 @@ func TestPoolExhaustOnCancel(t *testing.T) {
|
|||
if testing.Short() {
|
||||
t.Skip("long test")
|
||||
}
|
||||
db := newTestDB(t, "people")
|
||||
defer closeDB(t, db)
|
||||
|
||||
max := 3
|
||||
var saturate, saturateDone sync.WaitGroup
|
||||
saturate.Add(max)
|
||||
saturateDone.Add(max)
|
||||
|
||||
donePing := make(chan bool)
|
||||
state := 0
|
||||
|
||||
// waiter will be called for all queries, including
|
||||
// initial setup queries. The state is only assigned when no
|
||||
// no queries are made.
|
||||
//
|
||||
// Only allow the first batch of queries to finish once the
|
||||
// second batch of Ping queries have finished.
|
||||
waiter := func(ctx context.Context) {
|
||||
switch state {
|
||||
case 0:
|
||||
// Nothing. Initial database setup.
|
||||
case 1:
|
||||
saturate.Done()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-donePing:
|
||||
}
|
||||
case 2:
|
||||
}
|
||||
}
|
||||
db := newTestDBConnector(t, &fakeConnector{waiter: waiter}, "people")
|
||||
defer closeDB(t, db)
|
||||
|
||||
db.SetMaxOpenConns(max)
|
||||
|
||||
// First saturate the connection pool.
|
||||
// Then start new requests for a connection that is cancelled after it is requested.
|
||||
|
||||
state = 1
|
||||
var saturate, saturateDone sync.WaitGroup
|
||||
saturate.Add(max)
|
||||
saturateDone.Add(max)
|
||||
|
||||
for i := 0; i < max; i++ {
|
||||
go func() {
|
||||
rows, err := db.Query("SELECT|people|name,photo|")
|
||||
saturate.Done()
|
||||
rows, err := db.Query("WAIT|500ms|SELECT|people|name,photo|")
|
||||
if err != nil {
|
||||
t.Fatalf("Query: %v", err)
|
||||
}
|
||||
|
|
@ -636,7 +612,6 @@ func TestPoolExhaustOnCancel(t *testing.T) {
|
|||
}
|
||||
|
||||
saturate.Wait()
|
||||
state = 2
|
||||
|
||||
// Now cancel the request while it is waiting.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
|
|
@ -653,7 +628,7 @@ func TestPoolExhaustOnCancel(t *testing.T) {
|
|||
t.Fatalf("PingContext (Exhaust): %v", err)
|
||||
}
|
||||
}
|
||||
close(donePing)
|
||||
|
||||
saturateDone.Wait()
|
||||
|
||||
// Now try to open a normal connection.
|
||||
|
|
@ -1357,7 +1332,6 @@ func TestConnQuery(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn.dc.ci.(*fakeConn).skipDirtySession = true
|
||||
defer conn.Close()
|
||||
|
||||
var name string
|
||||
|
|
@ -1385,7 +1359,6 @@ func TestConnTx(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn.dc.ci.(*fakeConn).skipDirtySession = true
|
||||
defer conn.Close()
|
||||
|
||||
tx, err := conn.BeginTx(ctx, nil)
|
||||
|
|
@ -2411,9 +2384,7 @@ func TestManyErrBadConn(t *testing.T) {
|
|||
t.Fatalf("unexpected len(db.freeConn) %d (was expecting %d)", len(db.freeConn), nconn)
|
||||
}
|
||||
for _, conn := range db.freeConn {
|
||||
conn.Lock()
|
||||
conn.ci.(*fakeConn).stickyBad = true
|
||||
conn.Unlock()
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
|
@ -2503,7 +2474,6 @@ func TestManyErrBadConn(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn.dc.ci.(*fakeConn).skipDirtySession = true
|
||||
err = conn.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -3268,8 +3238,9 @@ func TestIssue18719(t *testing.T) {
|
|||
|
||||
// This call will grab the connection and cancel the context
|
||||
// after it has done so. Code after must deal with the canceled state.
|
||||
_, err = tx.QueryContext(ctx, "SELECT|people|name|")
|
||||
rows, err := tx.QueryContext(ctx, "SELECT|people|name|")
|
||||
if err != nil {
|
||||
rows.Close()
|
||||
t.Fatalf("expected error %v but got %v", nil, err)
|
||||
}
|
||||
|
||||
|
|
@ -3292,7 +3263,6 @@ func TestIssue20647(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conn.dc.ci.(*fakeConn).skipDirtySession = true
|
||||
defer conn.Close()
|
||||
|
||||
stmt, err := conn.PrepareContext(ctx, "SELECT|people|name|")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue