Skip to content

database/sql: use t.Context in tests #71599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions src/database/sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,7 @@ func TestConnQuery(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
conn, err := db.Conn(ctx)
if err != nil {
t.Fatal(err)
Expand All @@ -1402,8 +1401,7 @@ func TestConnRaw(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
conn, err := db.Conn(ctx)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1518,8 +1516,7 @@ func TestInvalidNilValues(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
conn, err := db.Conn(ctx)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1547,8 +1544,7 @@ func TestConnTx(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
conn, err := db.Conn(ctx)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -2793,8 +2789,7 @@ func TestManyErrBadConn(t *testing.T) {
// Conn
db = manyErrBadConnSetup()
defer closeDB(t, db)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
conn, err := db.Conn(ctx)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -2935,8 +2930,7 @@ func TestConnExpiresFreshOutOfPool(t *testing.T) {
}
defer func() { nowFunc = time.Now }()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

db := newTestDB(t, "magicquery")
defer closeDB(t, db)
Expand Down Expand Up @@ -3786,8 +3780,7 @@ func TestIssue20647(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

conn, err := db.Conn(ctx)
if err != nil {
Expand Down Expand Up @@ -4142,9 +4135,7 @@ func TestNamedValueChecker(t *testing.T) {
}
defer db.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

ctx := t.Context()
_, err = db.ExecContext(ctx, "WIPE")
if err != nil {
t.Fatal("exec wipe", err)
Expand Down Expand Up @@ -4192,9 +4183,7 @@ func TestNamedValueCheckerSkip(t *testing.T) {
}
defer db.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

ctx := t.Context()
_, err = db.ExecContext(ctx, "WIPE")
if err != nil {
t.Fatal("exec wipe", err)
Expand Down Expand Up @@ -4305,8 +4294,7 @@ func TestQueryExecContextOnly(t *testing.T) {
}
defer db.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

conn, err := db.Conn(ctx)
if err != nil {
Expand Down