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

Function TestWantConn_tryDeliver_Success

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

Source from the content-addressed store, hash-verified

39}
40
41func TestWantConn_tryDeliver_Success(t *testing.T) {
42 w := &wantConn{
43 ctx: context.Background(),
44 result: make(chan wantConnResult, 1),
45 }
46
47 // Create a mock connection
48 conn := &Conn{}
49
50 // Test successful delivery
51 delivered := w.tryDeliver(conn, nil)
52 if !delivered {
53 t.Error("tryDeliver() = false, want true")
54 }
55
56 // Check that wantConn is marked as done
57 if w.isOngoing() {
58 t.Error("wantConn.done = false, want true after delivery")
59 }
60
61 // Check that context is cleared
62 if w.getCtxForDial() != nil {
63 t.Error("wantConn.ctx should be nil after delivery")
64 }
65
66 // Check that result is sent
67 select {
68 case result := <-w.result:
69 if result.cn != conn {
70 t.Errorf("result.cn = %v, want %v", result.cn, conn)
71 }
72 if result.err != nil {
73 t.Errorf("result.err = %v, want nil", result.err)
74 }
75 case <-time.After(time.Millisecond):
76 t.Error("Expected result to be sent to channel")
77 }
78}
79
80func TestWantConn_tryDeliver_WithError(t *testing.T) {
81 w := &wantConn{

Callers

nothing calls this directly

Calls 4

tryDeliverMethod · 0.95
isOngoingMethod · 0.95
getCtxForDialMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected