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

Function TestWantConn_cancel_AlreadyDone

internal/pool/want_conn_test.go:165–193  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func TestWantConn_cancel_AlreadyDone(t *testing.T) {
166 w := &wantConn{
167 ctx: context.Background(),
168 done: true,
169 result: make(chan wantConnResult, 1),
170 }
171
172 // Put a result in the channel without connection (to avoid nil pointer issues)
173 testErr := errors.New("test error")
174 w.result <- wantConnResult{cn: nil, err: testErr}
175
176 // Test cancel when already done
177 cn := w.cancel()
178
179 // Should return nil since the result had no connection
180 if cn != nil {
181 t.Errorf("cancel()= %v, want nil when result had no connection", cn)
182 }
183
184 // Check that wantConn remains done
185 if w.isOngoing() {
186 t.Error("wantConn.done = false, want true")
187 }
188
189 // Check that context is cleared
190 if w.getCtxForDial() != nil {
191 t.Error("wantConn.ctx should be nil after cancel")
192 }
193}
194
195func TestWantConnQueue_newWantConnQueue(t *testing.T) {
196 q := newWantConnQueue()

Callers

nothing calls this directly

Calls 4

cancelMethod · 0.95
isOngoingMethod · 0.95
getCtxForDialMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected