MCPcopy
hub / github.com/pocketbase/pocketbase / TestBaseLockRetry

Function TestBaseLockRetry

core/db_retry_test.go:25–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23}
24
25func TestBaseLockRetry(t *testing.T) {
26 t.Parallel()
27
28 scenarios := []struct {
29 err error
30 failUntilAttempt int
31 expectedAttempts int
32 }{
33 {nil, 3, 1},
34 {errors.New("test"), 3, 1},
35 {errors.New("database is locked"), 3, 3},
36 {errors.New("table is locked"), 3, 3},
37 }
38
39 for i, s := range scenarios {
40 t.Run(fmt.Sprintf("%d_%#v", i, s.err), func(t *testing.T) {
41 lastAttempt := 0
42
43 err := baseLockRetry(func(attempt int) error {
44 lastAttempt = attempt
45
46 if attempt < s.failUntilAttempt {
47 return s.err
48 }
49
50 return nil
51 }, s.failUntilAttempt+2)
52
53 if lastAttempt != s.expectedAttempts {
54 t.Errorf("Expected lastAttempt to be %d, got %d", s.expectedAttempts, lastAttempt)
55 }
56
57 if s.failUntilAttempt == s.expectedAttempts && err != nil {
58 t.Fatalf("Expected nil, got err %v", err)
59 }
60
61 if s.failUntilAttempt != s.expectedAttempts && s.err != nil && err == nil {
62 t.Fatalf("Expected error %q, got nil", s.err)
63 }
64 })
65 }
66}

Callers

nothing calls this directly

Calls 2

baseLockRetryFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…