File tree 1 file changed +11
-2
lines changed
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
12
12
"context"
13
13
"database/sql"
14
14
"errors"
15
+ "flag"
15
16
"time"
16
17
17
18
"github.com/jmoiron/sqlx"
@@ -80,6 +81,16 @@ func (q *sqlQuerier) Ping(ctx context.Context) (time.Duration, error) {
80
81
return time .Since (start ), err
81
82
}
82
83
84
+ // retryAmount is an arbitrary number.
85
+ // Unit tests should disable retries.
86
+ var retryAmount = 3
87
+
88
+ func init () {
89
+ if flag .Lookup ("test.v" ) != nil {
90
+ retryAmount = 1
91
+ }
92
+ }
93
+
83
94
func (q * sqlQuerier ) InTx (function func (Store ) error , txOpts * sql.TxOptions ) error {
84
95
_ , inTx := q .db .(* sqlx.Tx )
85
96
isolation := sql .LevelDefault
@@ -93,8 +104,6 @@ func (q *sqlQuerier) InTx(function func(Store) error, txOpts *sql.TxOptions) err
93
104
// If we are in a transaction already, the parent InTx call will handle the retry.
94
105
// We do not want to duplicate those retries.
95
106
if ! inTx && isolation == sql .LevelSerializable {
96
- // This is an arbitrarily chosen number.
97
- const retryAmount = 3
98
107
var err error
99
108
attempts := 0
100
109
for attempts = 0 ; attempts < retryAmount ; attempts ++ {
You can’t perform that action at this time.
0 commit comments