Skip to content

Commit 7f3ee71

Browse files
authored
Adds a QueryFailTimes check to the test driver (#94)
* adds a QueryFailTimes check to the test driver * kick
1 parent cc7ea33 commit 7f3ee71

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

test/driver.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ func (s *SqlHandler) Query(args []driver.Value) (driver.Rows, error) {
7575
time.Sleep(time.Duration(s.Opts.QueryDelay * int(time.Second))) // simulate a query delay
7676
}
7777
s.row = 0
78-
if s.Opts.QueryError != nil {
78+
// only show the error if we have not exceeded the fail times and the error is not nil
79+
if s.Opts.QueryError != nil && (s.Opts.QueryFailTimes == 0 || s.State.QueryAttempts <= s.Opts.QueryFailTimes) {
7980
return s, s.Opts.QueryError
8081
}
82+
8183
return s, nil
8284
}
8385

@@ -148,10 +150,11 @@ func (s TestDS) Open() (*sql.DB, error) {
148150

149151
// DriverOpts the optional settings
150152
type DriverOpts struct {
151-
ConnectDelay int
152-
QueryDelay int
153-
ConnectError error
154-
QueryError error
153+
ConnectDelay int
154+
QueryDelay int
155+
ConnectError error
156+
QueryError error
157+
QueryFailTimes int
155158
}
156159

157160
// State is the state of the connections/queries

0 commit comments

Comments
 (0)