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

Function TestWantConn_cancel_NotDone

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

Source from the content-addressed store, hash-verified

128}
129
130func TestWantConn_cancel_NotDone(t *testing.T) {
131 w := &wantConn{
132 ctx: context.Background(),
133 result: make(chan wantConnResult, 1),
134 }
135
136 // Test cancel when not done
137 cn := w.cancel()
138
139 // Should return nil since no connection was not delivered
140 if cn != nil {
141 t.Errorf("cancel()= %v, want nil when no connection delivered", cn)
142 }
143
144 // Check that wantConn is marked as done
145 if w.isOngoing() {
146 t.Error("wantConn.done = false, want true after cancel")
147 }
148
149 // Check that context is cleared
150 if w.getCtxForDial() != nil {
151 t.Error("wantConn.ctx should be nil after cancel")
152 }
153
154 // Check that channel is closed
155 select {
156 case _, ok := <-w.result:
157 if ok {
158 t.Error("result channel should be closed after cancel")
159 }
160 case <-time.After(time.Millisecond):
161 t.Error("Expected channel to be closed")
162 }
163}
164
165func TestWantConn_cancel_AlreadyDone(t *testing.T) {
166 w := &wantConn{

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