aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/fakedb_test.go
diff options
context:
space:
mode:
authorChris Hines <chris.cs.guy@gmail.com>2015-08-24 21:48:39 -0400
committerBrad Fitzpatrick <bradfitz@golang.org>2015-09-03 17:07:37 +0000
commitd737639c4acce7c9f28de22eabfd623d0ae7ed50 (patch)
tree66e0ab6142e55f89a25cebe74f126405bac6c34f /src/database/sql/fakedb_test.go
parentbf99d8f843ae3dfa7a3a4cd5c17aec79e2b9997f (diff)
downloadgo-d737639c4acce7c9f28de22eabfd623d0ae7ed50.tar.xz
database/sql: close bad connections in commit or rollback:
Previously Tx.close always passed a nil error to tx.db.putConn. As a result bad connections were reused, even if the driver returned driver.ErrBadConn. Adding an err parameter to Tx.close allows it to receive the driver error from Tx.Commit and Tx.Rollback and pass it to tx.db.putConn. Fixes #11264 Change-Id: I142b6b2509fa8d714bbc135cef7281a40803b3b8 Reviewed-on: https://go-review.googlesource.com/13912 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/fakedb_test.go')
-rw-r--r--src/database/sql/fakedb_test.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/database/sql/fakedb_test.go b/src/database/sql/fakedb_test.go
index 8cbbb29a7c..112f280ec5 100644
--- a/src/database/sql/fakedb_test.go
+++ b/src/database/sql/fakedb_test.go
@@ -699,13 +699,25 @@ func (s *fakeStmt) NumInput() int {
return s.placeholders
}
+// hook to simulate broken connections
+var hookCommitBadConn func() bool
+
func (tx *fakeTx) Commit() error {
tx.c.currTx = nil
+ if hookCommitBadConn != nil && hookCommitBadConn() {
+ return driver.ErrBadConn
+ }
return nil
}
+// hook to simulate broken connections
+var hookRollbackBadConn func() bool
+
func (tx *fakeTx) Rollback() error {
tx.c.currTx = nil
+ if hookRollbackBadConn != nil && hookRollbackBadConn() {
+ return driver.ErrBadConn
+ }
return nil
}