(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func TestCleanupByTimer(t *testing.T) { |
| 54 | s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) { |
| 55 | ret := new(dns.Msg) |
| 56 | ret.SetReply(r) |
| 57 | w.WriteMsg(ret) |
| 58 | }) |
| 59 | defer s.Close() |
| 60 | |
| 61 | tr := newTransport("TestCleanupByTimer", s.Addr) |
| 62 | tr.SetExpire(100 * time.Millisecond) |
| 63 | tr.Start() |
| 64 | defer tr.Stop() |
| 65 | |
| 66 | c1, _, _ := tr.Dial("udp") |
| 67 | c2, _, _ := tr.Dial("udp") |
| 68 | tr.Yield(c1) |
| 69 | time.Sleep(10 * time.Millisecond) |
| 70 | tr.Yield(c2) |
| 71 | |
| 72 | time.Sleep(120 * time.Millisecond) |
| 73 | c3, cached, _ := tr.Dial("udp") |
| 74 | if cached { |
| 75 | t.Error("Expected non-cached connection (c3)") |
| 76 | } |
| 77 | tr.Yield(c3) |
| 78 | |
| 79 | time.Sleep(120 * time.Millisecond) |
| 80 | c4, cached, _ := tr.Dial("udp") |
| 81 | if cached { |
| 82 | t.Error("Expected non-cached connection (c4)") |
| 83 | } |
| 84 | tr.Yield(c4) |
| 85 | } |
| 86 | |
| 87 | func TestCleanupAll(t *testing.T) { |
| 88 | s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…