MCPcopy
hub / github.com/coredns/coredns / TestMaxAgeFIFORotation

Function TestMaxAgeFIFORotation

plugin/pkg/proxy/persistent_test.go:277–315  ·  view source on GitHub ↗

TestMaxAgeFIFORotation verifies that connections in a FIFO pool are closed by max_age even when continuously rotated (which refreshes their used timestamps). Regression test for Scale up: new upstream pods should receive traffic after existing connections exceed max_age, regardless of request rate.

(t *testing.T)

Source from the content-addressed store, hash-verified

275// Regression test for Scale up: new upstream pods should receive traffic after
276// existing connections exceed max_age, regardless of request rate.
277func TestMaxAgeFIFORotation(t *testing.T) {
278 s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
279 ret := new(dns.Msg)
280 ret.SetReply(r)
281 w.WriteMsg(ret)
282 })
283 defer s.Close()
284
285 tr := newTransport("TestMaxAgeFIFORotation", s.Addr)
286 tr.SetExpire(10 * time.Second) // long idle-timeout: FIFO rotation keeps connections alive
287 tr.SetMaxAge(100 * time.Millisecond) // max-age: connections must be closed by creation age
288 tr.Start()
289 defer tr.Stop()
290
291 // Inject 3 connections old by creation time but with fresh used timestamps,
292 // simulating active FIFO rotation where idle-timeout never triggers.
293 tr.mu.Lock()
294 for range 3 {
295 c, err := dns.DialTimeout("udp", tr.addr, maxDialTimeout)
296 if err != nil {
297 tr.mu.Unlock()
298 t.Fatalf("Failed to dial: %v", err)
299 }
300 tr.conns[typeUDP] = append(tr.conns[typeUDP], &persistConn{
301 c: c,
302 created: time.Now().Add(-200 * time.Millisecond), // exceeds max-age
303 used: time.Now(), // fresh: idle-timeout would pass
304 })
305 }
306 tr.mu.Unlock()
307
308 // All 3 connections must be rejected by max_age despite fresh used timestamps.
309 for i := range 3 {
310 _, cached, _ := tr.Dial("udp")
311 if cached {
312 t.Errorf("Dial %d: connection should be closed by max_age (FIFO rotation must not prevent max-age expiry)", i+1)
313 }
314 }
315}
316
317func BenchmarkYield(b *testing.B) {
318 s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
NewServerFunction · 0.92
newTransportFunction · 0.85
DialMethod · 0.80
StopMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65
WriteMsgMethod · 0.45
SetExpireMethod · 0.45
SetMaxAgeMethod · 0.45
StartMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…