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)
| 275 | // Regression test for Scale up: new upstream pods should receive traffic after |
| 276 | // existing connections exceed max_age, regardless of request rate. |
| 277 | func 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 | |
| 317 | func BenchmarkYield(b *testing.B) { |
| 318 | s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…