Skip to content

Commit f238f1d

Browse files
committed
refactor retry/sql_test and upload with off gocognit linter and undo last commit with log/table
1 parent 14394d5 commit f238f1d

File tree

2 files changed

+52
-35
lines changed

2 files changed

+52
-35
lines changed

CHANGELOG.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
* Refactored `internal/topic/topicwriterinternal/queue_test.go` and extract funcs
2-
* Refactored `log/driver.go` and extract funcs
3-
* Refactored `internal/table/scanner/scanner.go` and extract funcs
4-
* Refactored `log/topic.go` and extract funcs
5-
* Refactored `internal/table/scanner/scanner_test.go` and extract funcs
6-
* Refactored `log/sql.go` and extract funcs
7-
* Refactored `metrics/driver.go` and extract funcs
8-
* Refactored `metrics/sql.go` and extract funcs
9-
* Refactored `internal/table/retry_test.go` and extract func `retry_test.checkResultsRetryWithCustomErrors`
10-
* Refactored `internal/table/client.go` and extract func `client.onCloseSession`
11-
* Refactored `internal/decimal/decimal.go` and extract func `decimal.dotStringAnalysis`
12-
* Refactored `internal/backoff/backoff_test.go` and extract func `backoff_test.checkExpWithAct` for compare
13-
* Refactored `internal/xsql/dsn.go` and extract func `dsn.bindTablePathPrefixInConnectorOptions`
14-
* Refactored `sugar/path.go` and extract funcs `path.removeWithPrefix`, `path.removeEntry`
15-
* Refactored `internal/stack/record.go` and extract func `record.findFileNameAndPkgPath`
1+
* Refactored `retry/sql_test.go` and extract func `sql_test.canRetry` for gocognit linter
2+
* Refactored `internal/topic/topicwriterinternal/queue_test.go` and extract funcs for gocognit linter
3+
* Refactored `log/driver.go` and extract funcs for gocognit linter
4+
* Refactored `internal/table/scanner/scanner.go` and extract funcs for gocognit linter
5+
* Refactored `log/topic.go` and extract funcs for gocognit linter
6+
* Refactored `internal/table/scanner/scanner_test.go` and extract funcs for gocognit linter
7+
* Refactored `log/sql.go` and extract funcs for gocognit linter
8+
* Refactored `metrics/driver.go` and extract funcs for gocognit linter
9+
* Refactored `metrics/sql.go` and extract funcs for gocognit linter
10+
* Refactored `internal/table/retry_test.go` and extract func `retry_test.checkResultsRetryWithCustomErrors` for gocognit linter
11+
* Refactored `internal/table/client.go` and extract func `client.onCloseSession` for gocognit linter
12+
* Refactored `internal/decimal/decimal.go` and extract func `decimal.dotStringAnalysis` for gocognit linter
13+
* Refactored `internal/backoff/backoff_test.go` and extract func `backoff_test.checkExpWithAct` for gocognit linter
14+
* Refactored `internal/xsql/dsn.go` and extract func `dsn.bindTablePathPrefixInConnectorOptions` for gocognit linter
15+
* Refactored `sugar/path.go` and extract funcs `path.removeWithPrefix`, `path.removeEntry` for gocognit linter
16+
* Refactored `internal/stack/record.go` and extract func `record.findFileNameAndPkgPath` for gocognit linter
1617
* Fixed topic writer infinite reconnections in some cases
1718
* Refactored nil on err `internal/grpcwrapper/rawydb/issues.go`, when golangci-lint nilerr enabled
1819
* Refactored nil on err `internal/grpcwrapper/rawtopic/describe_topic.go`, when golangci-lint nilerr enabled

retry/sql_test.go

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ func (m *mockStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (
180180
return m.conn.QueryContext(ctx, m.query, args)
181181
}
182182

183-
//nolint:nestif
184183
func TestDoTx(t *testing.T) {
185184
for _, idempotentType := range []idempotency{
186185
idempotent,
@@ -228,27 +227,44 @@ func TestDoTx(t *testing.T) {
228227
},
229228
}),
230229
)
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)
250231
})
251232
}
252233
})
253234
}
254235
}
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

Comments
 (0)