(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestCached(t *testing.T) { |
| 14 | s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) { |
| 15 | ret := new(dns.Msg) |
| 16 | ret.SetReply(r) |
| 17 | w.WriteMsg(ret) |
| 18 | }) |
| 19 | defer s.Close() |
| 20 | |
| 21 | tr := newTransport("TestCached", s.Addr) |
| 22 | tr.Start() |
| 23 | defer tr.Stop() |
| 24 | |
| 25 | c1, cache1, _ := tr.Dial("udp") |
| 26 | c2, cache2, _ := tr.Dial("udp") |
| 27 | |
| 28 | if cache1 || cache2 { |
| 29 | t.Errorf("Expected non-cached connection") |
| 30 | } |
| 31 | |
| 32 | tr.Yield(c1) |
| 33 | tr.Yield(c2) |
| 34 | c3, cached3, _ := tr.Dial("udp") |
| 35 | if !cached3 { |
| 36 | t.Error("Expected cached connection (c3)") |
| 37 | } |
| 38 | // FIFO: first yielded (c1) should be first out |
| 39 | if c1 != c3 { |
| 40 | t.Error("Expected c1 == c3 (FIFO order)") |
| 41 | } |
| 42 | |
| 43 | tr.Yield(c3) |
| 44 | |
| 45 | // dial another protocol |
| 46 | c4, cached4, _ := tr.Dial("tcp") |
| 47 | if cached4 { |
| 48 | t.Errorf("Expected non-cached connection (c4)") |
| 49 | } |
| 50 | tr.Yield(c4) |
| 51 | } |
| 52 | |
| 53 | func TestCleanupByTimer(t *testing.T) { |
| 54 | s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…