MCPcopy
hub / github.com/coredns/coredns / TestMaxIdleConns

Function TestMaxIdleConns

plugin/pkg/proxy/persistent_test.go:118–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

116}
117
118func TestMaxIdleConns(t *testing.T) {
119 s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
120 ret := new(dns.Msg)
121 ret.SetReply(r)
122 w.WriteMsg(ret)
123 })
124 defer s.Close()
125
126 tr := newTransport("TestMaxIdleConns", s.Addr)
127 tr.SetMaxIdleConns(2) // Limit to 2 connections per type
128 tr.Start()
129 defer tr.Stop()
130
131 // Dial 3 connections
132 c1, _, _ := tr.Dial("udp")
133 c2, _, _ := tr.Dial("udp")
134 c3, _, _ := tr.Dial("udp")
135
136 // Yield all 3
137 tr.Yield(c1)
138 tr.Yield(c2)
139 tr.Yield(c3) // This should be discarded (pool full)
140
141 // Check pool size is capped at 2
142 tr.mu.Lock()
143 poolSize := len(tr.conns[typeUDP])
144 tr.mu.Unlock()
145
146 if poolSize != 2 {
147 t.Errorf("Expected pool size 2, got %d", poolSize)
148 }
149
150 // Verify we get the first 2 back (FIFO)
151 d1, cached1, _ := tr.Dial("udp")
152 d2, cached2, _ := tr.Dial("udp")
153 _, cached3, _ := tr.Dial("udp")
154
155 if !cached1 || !cached2 {
156 t.Error("Expected first 2 dials to be cached")
157 }
158 if cached3 {
159 t.Error("Expected 3rd dial to be non-cached (pool was limited to 2)")
160 }
161 if d1 != c1 || d2 != c2 {
162 t.Error("Expected FIFO order: d1==c1, d2==c2")
163 }
164}
165
166func TestMaxIdleConnsUnlimited(t *testing.T) {
167 s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
NewServerFunction · 0.92
newTransportFunction · 0.85
DialMethod · 0.80
YieldMethod · 0.80
StopMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.65
WriteMsgMethod · 0.45
SetMaxIdleConnsMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…