@@ -180,7 +180,6 @@ func (m *mockStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (
180
180
return m .conn .QueryContext (ctx , m .query , args )
181
181
}
182
182
183
- //nolint:nestif
184
183
func TestDoTx (t * testing.T ) {
185
184
for _ , idempotentType := range []idempotency {
186
185
idempotent ,
@@ -228,27 +227,44 @@ func TestDoTx(t *testing.T) {
228
227
},
229
228
}),
230
229
)
231
- if tt .canRetry [idempotentType ] {
232
- if err != nil {
233
- t .Errorf ("unexpected err after attempts=%d and driver conns=%d: %v)" , attempts , m .conns , err )
234
- }
235
- if attempts <= 1 {
236
- t .Errorf ("must be attempts > 1 (actual=%d), driver conns=%d)" , attempts , m .conns )
237
- }
238
- if tt .deleteSession {
239
- if m .conns <= 1 {
240
- t .Errorf ("must be retry on different conns (attempts=%d, driver conns=%d)" , attempts , m .conns )
241
- }
242
- } else {
243
- if m .conns > 1 {
244
- t .Errorf ("must be retry on single conn (attempts=%d, driver conns=%d)" , attempts , m .conns )
245
- }
246
- }
247
- } else if err == nil {
248
- t .Errorf ("unexpected nil err (attempts=%d, driver conns=%d)" , attempts , m .conns )
249
- }
230
+ canRetry (t , tt , idempotentType , err , attempts , m )
250
231
})
251
232
}
252
233
})
253
234
}
254
235
}
236
+
237
+ // canRetry checks if a retry can be performed based on the given parameters.
238
+ //
239
+ //nolint:nestif
240
+ func canRetry (t * testing.T , tt struct {
241
+ err error
242
+ backoff backoff.Type
243
+ deleteSession bool
244
+ canRetry map [idempotency ]bool
245
+ },
246
+ idempotentType idempotency ,
247
+ err error ,
248
+ attempts int ,
249
+ m * mockConnector ,
250
+ ) {
251
+ if tt .canRetry [idempotentType ] {
252
+ if err != nil {
253
+ t .Errorf ("unexpected err after attempts=%d and driver conns=%d: %v)" , attempts , m .conns , err )
254
+ }
255
+ if attempts <= 1 {
256
+ t .Errorf ("must be attempts > 1 (actual=%d), driver conns=%d)" , attempts , m .conns )
257
+ }
258
+ if tt .deleteSession {
259
+ if m .conns <= 1 {
260
+ t .Errorf ("must be retry on different conns (attempts=%d, driver conns=%d)" , attempts , m .conns )
261
+ }
262
+ } else {
263
+ if m .conns > 1 {
264
+ t .Errorf ("must be retry on single conn (attempts=%d, driver conns=%d)" , attempts , m .conns )
265
+ }
266
+ }
267
+ } else if err == nil {
268
+ t .Errorf ("unexpected nil err (attempts=%d, driver conns=%d)" , attempts , m .conns )
269
+ }
270
+ }
0 commit comments