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

Function TestHookShouldRemove

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

Source from the content-addressed store, hash-verified

141}
142
143func TestHookShouldRemove(t *testing.T) {
144 manager := NewPoolHookManager()
145
146 // Hook that says to remove connection
147 removeHook := &TestHook{
148 ShouldPool: false,
149 ShouldRemove: true,
150 ShouldAccept: true,
151 }
152
153 normalHook := &TestHook{ShouldPool: true, ShouldAccept: true}
154
155 manager.AddHook(removeHook)
156 manager.AddHook(normalHook)
157
158 ctx := context.Background()
159 conn := &Conn{}
160
161 shouldPool, shouldRemove, err := manager.ProcessOnPut(ctx, conn)
162 if err != nil {
163 t.Errorf("ProcessOnPut should not error: %v", err)
164 }
165
166 if shouldPool {
167 t.Error("Expected shouldPool to be false")
168 }
169
170 if !shouldRemove {
171 t.Error("Expected shouldRemove to be true")
172 }
173
174 if removeHook.OnPutCalled != 1 {
175 t.Errorf("Expected removeHook.OnPutCalled to be 1, got %d", removeHook.OnPutCalled)
176 }
177
178 // normalHook should not be called due to early return
179 if normalHook.OnPutCalled != 0 {
180 t.Errorf("Expected normalHook.OnPutCalled to be 0, got %d", normalHook.OnPutCalled)
181 }
182}
183
184func TestPoolWithHooks(t *testing.T) {
185 // Create a pool with hooks

Callers

nothing calls this directly

Calls 4

AddHookMethod · 0.95
ProcessOnPutMethod · 0.95
NewPoolHookManagerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected