Skip to content
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

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

Merged
merged 1 commit into from
Jan 27, 2019

Conversation

peergynt
Copy link
Contributor

@peergynt peergynt commented Jan 25, 2019

Description

Close rows after we are done using them avoids having a bunch of connections hanging around.

Checklist

  • Code compiles correctly
  • All tests passing
  • Added myself / the copyright holder to the AUTHORS file

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()
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@peergynt
Copy link
Contributor Author

@methane I took another stab at this PR:

  • I switched all deferred row Close to a plain row Close in loops
  • I found 3 more rows that were not being closed
  • I used deferred row Close when the test could possibly exit prematurely (with testing.Fatalf for instance)

@methane methane merged commit 1b9eda2 into go-sql-driver:master Jan 27, 2019
@julienschmidt julienschmidt added this to the v1.5.0 milestone Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants