MCPcopy
hub / github.com/redis/go-redis / TestHookErrorHandling

Function TestHookErrorHandling

internal/pool/hooks_test.go:106–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestHookErrorHandling(t *testing.T) {
107 manager := NewPoolHookManager()
108
109 // Hook that returns error on Get
110 errorHook := &TestHook{
111 GetError: errors.New("test error"),
112 ShouldPool: true,
113 ShouldAccept: true,
114 }
115
116 normalHook := &TestHook{ShouldPool: true, ShouldAccept: true}
117
118 manager.AddHook(errorHook)
119 manager.AddHook(normalHook)
120
121 ctx := context.Background()
122 conn := &Conn{}
123
124 // Test that error stops processing
125 accept, err := manager.ProcessOnGet(ctx, conn, false)
126 if err == nil {
127 t.Error("Expected error from ProcessOnGet")
128 }
129 if accept {
130 t.Error("Expected accept to be false")
131 }
132
133 if errorHook.OnGetCalled != 1 {
134 t.Errorf("Expected errorHook.OnGetCalled to be 1, got %d", errorHook.OnGetCalled)
135 }
136
137 // normalHook should not be called due to error
138 if normalHook.OnGetCalled != 0 {
139 t.Errorf("Expected normalHook.OnGetCalled to be 0, got %d", normalHook.OnGetCalled)
140 }
141}
142
143func TestHookShouldRemove(t *testing.T) {
144 manager := NewPoolHookManager()

Callers

nothing calls this directly

Calls 4

AddHookMethod · 0.95
ProcessOnGetMethod · 0.95
NewPoolHookManagerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected