Procházet zdrojové kódy

test: close rows (#918)

Jerome Meyer před 6 roky
rodič
revize
1b9eda2502
2 změnil soubory, kde provedl 23 přidání a 1 odebrání
  1. 1 0
      AUTHORS
  2. 22 1
      driver_test.go

+ 1 - 0
AUTHORS

@@ -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>

+ 22 - 1
driver_test.go

@@ -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")
@@ -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)")
@@ -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)
@@ -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)
@@ -351,6 +355,7 @@ func TestMultiQuery(t *testing.T) {
 		} else {
 			dbt.Error("no data")
 		}
+		rows.Close()
 
 	})
 }
@@ -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")
 		}
@@ -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")
 		}
@@ -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")
 		}
 	})
@@ -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")
 		}
 	})
@@ -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")
 		}
 	})
@@ -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")
 		}
@@ -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 {
@@ -572,6 +584,7 @@ func TestValuer(t *testing.T) {
 		} else {
 			dbt.Errorf("Valuer: no data")
 		}
+		rows.Close()
 
 		dbt.mustExec("DROP TABLE IF EXISTS test")
 	})
@@ -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")
 		}
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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() {
@@ -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))
@@ -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")
 		}
@@ -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)
@@ -2030,6 +2050,7 @@ func TestInterruptBySignal(t *testing.T) {
 				dbt.Errorf("expected val to be 42")
 			}
 		}
+		rows.Close()
 	})
 }