Skip to content

Tests cleanup: close rows when done to avoid resource leak during testing #918

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

Merged
merged 1 commit into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Jacek Szwec <szwec.jacek at gmail.com>
James Harr <james.harr at gmail.com>
Jeff Hodges <jeff at somethingsimilar.com>
Jeffrey Charles <jeffreycharles at gmail.com>
Jerome Meyer <jxmeyer at gmail.com>
Jian Zhen <zhenjl at gmail.com>
Joshua Prunier <joshua.prunier at gmail.com>
Julien Lefevre <julien.lefevr at gmail.com>
Expand Down
23 changes: 22 additions & 1 deletion driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func TestEmptyQuery(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
// just a comment, no query
rows := dbt.mustQuery("--")
defer rows.Close()
// will hang before #255
if rows.Next() {
dbt.Errorf("next on rows must be false")
Expand All @@ -230,6 +231,7 @@ func TestCRUD(t *testing.T) {
if rows.Next() {
dbt.Error("unexpected data in empty table")
}
rows.Close()

// Create Data
res := dbt.mustExec("INSERT INTO test VALUES (1)")
Expand Down Expand Up @@ -263,6 +265,7 @@ func TestCRUD(t *testing.T) {
} else {
dbt.Error("no data")
}
rows.Close()

// Update
res = dbt.mustExec("UPDATE test SET value = ? WHERE value = ?", false, true)
Expand All @@ -288,6 +291,7 @@ func TestCRUD(t *testing.T) {
} else {
dbt.Error("no data")
}
rows.Close()

// Delete
res = dbt.mustExec("DELETE FROM test WHERE value = ?", false)
Expand Down Expand Up @@ -351,6 +355,7 @@ func TestMultiQuery(t *testing.T) {
} else {
dbt.Error("no data")
}
rows.Close()

})
}
Expand All @@ -377,6 +382,7 @@ func TestInt(t *testing.T) {
} else {
dbt.Errorf("%s: no data", v)
}
rows.Close()

dbt.mustExec("DROP TABLE IF EXISTS test")
}
Expand All @@ -396,6 +402,7 @@ func TestInt(t *testing.T) {
} else {
dbt.Errorf("%s ZEROFILL: no data", v)
}
rows.Close()

dbt.mustExec("DROP TABLE IF EXISTS test")
}
Expand All @@ -420,6 +427,7 @@ func TestFloat32(t *testing.T) {
} else {
dbt.Errorf("%s: no data", v)
}
rows.Close()
dbt.mustExec("DROP TABLE IF EXISTS test")
}
})
Expand All @@ -443,6 +451,7 @@ func TestFloat64(t *testing.T) {
} else {
dbt.Errorf("%s: no data", v)
}
rows.Close()
dbt.mustExec("DROP TABLE IF EXISTS test")
}
})
Expand All @@ -466,6 +475,7 @@ func TestFloat64Placeholder(t *testing.T) {
} else {
dbt.Errorf("%s: no data", v)
}
rows.Close()
dbt.mustExec("DROP TABLE IF EXISTS test")
}
})
Expand All @@ -492,6 +502,7 @@ func TestString(t *testing.T) {
} else {
dbt.Errorf("%s: no data", v)
}
rows.Close()

dbt.mustExec("DROP TABLE IF EXISTS test")
}
Expand Down Expand Up @@ -524,6 +535,7 @@ func TestRawBytes(t *testing.T) {
v1 := []byte("aaa")
v2 := []byte("bbb")
rows := dbt.mustQuery("SELECT ?, ?", v1, v2)
defer rows.Close()
if rows.Next() {
var o1, o2 sql.RawBytes
if err := rows.Scan(&o1, &o2); err != nil {
Expand Down Expand Up @@ -572,6 +584,7 @@ func TestValuer(t *testing.T) {
} else {
dbt.Errorf("Valuer: no data")
}
rows.Close()

dbt.mustExec("DROP TABLE IF EXISTS test")
})
Expand Down Expand Up @@ -884,6 +897,7 @@ func TestTimestampMicros(t *testing.T) {
dbt.mustExec("INSERT INTO test SET value0=?, value1=?, value6=?", f0, f1, f6)
var res0, res1, res6 string
rows := dbt.mustQuery("SELECT * FROM test")
defer rows.Close()
if !rows.Next() {
dbt.Errorf("test contained no selectable values")
}
Expand Down Expand Up @@ -1042,6 +1056,7 @@ func TestNULL(t *testing.T) {

var out interface{}
rows := dbt.mustQuery("SELECT * FROM test")
defer rows.Close()
if rows.Next() {
rows.Scan(&out)
if out != nil {
Expand Down Expand Up @@ -1121,6 +1136,7 @@ func TestLongData(t *testing.T) {
inS := in[:maxAllowedPacketSize-nonDataQueryLen]
dbt.mustExec("INSERT INTO test VALUES('" + inS + "')")
rows = dbt.mustQuery("SELECT value FROM test")
defer rows.Close()
if rows.Next() {
rows.Scan(&out)
if inS != out {
Expand All @@ -1139,6 +1155,7 @@ func TestLongData(t *testing.T) {
// Long binary data
dbt.mustExec("INSERT INTO test VALUES(?)", in)
rows = dbt.mustQuery("SELECT value FROM test WHERE 1=?", 1)
defer rows.Close()
if rows.Next() {
rows.Scan(&out)
if in != out {
Expand Down Expand Up @@ -1314,6 +1331,7 @@ func TestTLS(t *testing.T) {
}

rows := dbt.mustQuery("SHOW STATUS LIKE 'Ssl_cipher'")
defer rows.Close()

var variable, value *sql.RawBytes
for rows.Next() {
Expand Down Expand Up @@ -1474,9 +1492,9 @@ func TestColumnsWithAlias(t *testing.T) {
if cols[0] != "A" {
t.Fatalf("expected column name \"A\", got \"%s\"", cols[0])
}
rows.Close()

rows = dbt.mustQuery("SELECT * FROM (SELECT 1 AS one) AS A")
defer rows.Close()
cols, _ = rows.Columns()
if len(cols) != 1 {
t.Fatalf("expected 1 column, got %d", len(cols))
Expand Down Expand Up @@ -1520,6 +1538,7 @@ func TestTimezoneConversion(t *testing.T) {

// Retrieve time from DB
rows := dbt.mustQuery("SELECT ts FROM test")
defer rows.Close()
if !rows.Next() {
dbt.Fatal("did not get any rows out")
}
Expand Down Expand Up @@ -2017,6 +2036,7 @@ func TestInterruptBySignal(t *testing.T) {
dbt.Errorf("expected val to be 42")
}
}
rows.Close()

// binary protocol
rows, err = dbt.db.Query("CALL test_signal(?)", 42)
Expand All @@ -2030,6 +2050,7 @@ func TestInterruptBySignal(t *testing.T) {
dbt.Errorf("expected val to be 42")
}
}
rows.Close()
})
}

Expand Down