-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
driver_test.go
Outdated
@@ -248,6 +249,7 @@ func TestCRUD(t *testing.T) { | |||
if id != 0 { | |||
dbt.Fatalf("expected InsertId 0, got %d", id) | |||
} | |||
rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved to L233
driver_test.go
Outdated
@@ -339,6 +343,7 @@ func TestMultiQuery(t *testing.T) { | |||
// Read | |||
var out int | |||
rows := dbt.mustQuery("SELECT value FROM test WHERE id=1;") | |||
defer rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use defer rows.Close()
in loop.
driver_test.go
Outdated
@@ -369,6 +374,7 @@ func TestInt(t *testing.T) { | |||
dbt.mustExec("INSERT INTO test VALUES (?)", in) | |||
|
|||
rows = dbt.mustQuery("SELECT value FROM test") | |||
defer rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use defer rows.Close()
in loop.
driver_test.go
Outdated
@@ -388,6 +394,7 @@ func TestInt(t *testing.T) { | |||
dbt.mustExec("INSERT INTO test VALUES (?)", in) | |||
|
|||
rows = dbt.mustQuery("SELECT value FROM test") | |||
defer rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
driver_test.go
Outdated
@@ -412,6 +419,7 @@ func TestFloat32(t *testing.T) { | |||
dbt.mustExec("CREATE TABLE test (value " + v + ")") | |||
dbt.mustExec("INSERT INTO test VALUES (?)", in) | |||
rows = dbt.mustQuery("SELECT value FROM test") | |||
defer rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
driver_test.go
Outdated
@@ -435,6 +443,7 @@ func TestFloat64(t *testing.T) { | |||
dbt.mustExec("CREATE TABLE test (value " + v + ")") | |||
dbt.mustExec("INSERT INTO test VALUES (42.23)") | |||
rows = dbt.mustQuery("SELECT value FROM test") | |||
defer rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
driver_test.go
Outdated
@@ -458,6 +467,7 @@ func TestFloat64Placeholder(t *testing.T) { | |||
dbt.mustExec("CREATE TABLE test (id int, value " + v + ")") | |||
dbt.mustExec("INSERT INTO test VALUES (1, 42.23)") | |||
rows = dbt.mustQuery("SELECT value FROM test WHERE id = ?", 1) | |||
defer rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
driver_test.go
Outdated
@@ -484,6 +494,7 @@ func TestString(t *testing.T) { | |||
dbt.mustExec("INSERT INTO test VALUES (?)", in) | |||
|
|||
rows = dbt.mustQuery("SELECT value FROM test") | |||
defer rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@methane I took another stab at this PR:
|
Description
Close rows after we are done using them avoids having a bunch of connections hanging around.
Checklist