mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: add context methods
Add context methods to sql and sql/driver methods. If the driver doesn't implement context methods the connection pool will still handle timeouts when a query fails to return in time or when a connection is not available from the pool in time. There will be a follow-up CL that will add support for context values that specify transaction levels and modes that a driver can use. Fixes #15123 Change-Id: Ia99f3957aa3f177b23044dd99d4ec217491a30a7 Reviewed-on: https://go-review.googlesource.com/29381 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
54a72d90f6
commit
e13df02e5f
5 changed files with 534 additions and 109 deletions
|
|
@ -5,6 +5,7 @@
|
|||
package sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -1159,17 +1160,19 @@ func TestMaxOpenConnsOnBusy(t *testing.T) {
|
|||
|
||||
db.SetMaxOpenConns(3)
|
||||
|
||||
conn0, err := db.conn(cachedOrNewConn)
|
||||
ctx := context.Background()
|
||||
|
||||
conn0, err := db.conn(ctx, cachedOrNewConn)
|
||||
if err != nil {
|
||||
t.Fatalf("db open conn fail: %v", err)
|
||||
}
|
||||
|
||||
conn1, err := db.conn(cachedOrNewConn)
|
||||
conn1, err := db.conn(ctx, cachedOrNewConn)
|
||||
if err != nil {
|
||||
t.Fatalf("db open conn fail: %v", err)
|
||||
}
|
||||
|
||||
conn2, err := db.conn(cachedOrNewConn)
|
||||
conn2, err := db.conn(ctx, cachedOrNewConn)
|
||||
if err != nil {
|
||||
t.Fatalf("db open conn fail: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue