Skip to content

Commit 3343652

Browse files
committed
refactor internal/table/retry_test and upload with off gocognit linter
1 parent 9d5e827 commit 3343652

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Refactored `internal/table/retry_test.go` and extract func `retry_test.checkResultsRetryWithCustomErrors`
12
* Refactored `internal/table/client.go` and extract func `client.onCloseSession`
23
* Refactored `internal/decimal/decimal.go` and extract func `decimal.dotStringAnalysis`
34
* Refactored `internal/backoff/backoff_test.go` and extract func `backoff_test.checkExpWithAct` for compare

internal/table/retry_test.go

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -457,30 +457,44 @@ func TestRetryWithCustomErrors(t *testing.T) {
457457
},
458458
nil,
459459
)
460-
//nolint:nestif
461-
if test.retriable {
462-
if i != limit {
463-
t.Fatalf("unexpected i: %d, err: %v", i, err)
464-
}
465-
if test.deleteSession {
466-
if len(sessions) != limit {
467-
t.Fatalf("unexpected len(sessions): %d, err: %v", len(sessions), err)
468-
}
469-
for s, n := range sessions {
470-
if n != 1 {
471-
t.Fatalf("unexpected session usage: %d, session: %v", n, s.ID())
472-
}
473-
}
474-
}
475-
} else {
476-
if i != 1 {
477-
t.Fatalf("unexpected i: %d, err: %v", i, err)
478-
}
479-
if len(sessions) != 1 {
480-
t.Fatalf("unexpected len(sessions): %d, err: %v", len(sessions), err)
460+
checkResultsRetryWithCustomErrors(t, test, i, limit, err, sessions)
461+
})
462+
}
463+
}
464+
465+
// checkResultsRetryWithCustomErrors is a helper function for testing all suspensions of a custom operation function
466+
// against all deadlines.
467+
func checkResultsRetryWithCustomErrors(t *testing.T, test struct {
468+
error error
469+
retriable bool
470+
deleteSession bool
471+
}, i int,
472+
limit int,
473+
err error,
474+
sessions map[table.Session]int,
475+
) {
476+
//nolint:nestif
477+
if test.retriable {
478+
if i != limit {
479+
t.Fatalf("unexpected i: %d, err: %v", i, err)
480+
}
481+
if test.deleteSession {
482+
if len(sessions) != limit {
483+
t.Fatalf("unexpected len(sessions): %d, err: %v", len(sessions), err)
484+
}
485+
for s, n := range sessions {
486+
if n != 1 {
487+
t.Fatalf("unexpected session usage: %d, session: %v", n, s.ID())
481488
}
482489
}
483-
})
490+
}
491+
} else {
492+
if i != 1 {
493+
t.Fatalf("unexpected i: %d, err: %v", i, err)
494+
}
495+
if len(sessions) != 1 {
496+
t.Fatalf("unexpected len(sessions): %d, err: %v", len(sessions), err)
497+
}
484498
}
485499
}
486500

0 commit comments

Comments
 (0)