MCPcopy
hub / github.com/coredns/coredns / TestCached

Function TestCached

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

Source from the content-addressed store, hash-verified

11)
12
13func 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
53func TestCleanupByTimer(t *testing.T) {
54 s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {

Callers

nothing calls this directly

Calls 10

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
StartMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…