aboutsummaryrefslogtreecommitdiff
path: root/plugin/forward/persistent_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/forward/persistent_test.go')
-rw-r--r--plugin/forward/persistent_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/plugin/forward/persistent_test.go b/plugin/forward/persistent_test.go
new file mode 100644
index 000000000..5674658e6
--- /dev/null
+++ b/plugin/forward/persistent_test.go
@@ -0,0 +1,44 @@
+package forward
+
+import (
+ "testing"
+
+ "github.com/coredns/coredns/plugin/pkg/dnstest"
+
+ "github.com/miekg/dns"
+)
+
+func TestPersistent(t *testing.T) {
+ s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
+ ret := new(dns.Msg)
+ ret.SetReply(r)
+ w.WriteMsg(ret)
+ })
+ defer s.Close()
+
+ h := newHost(s.Addr)
+ tr := newTransport(h)
+ defer tr.Stop()
+
+ c1, _ := tr.Dial("udp")
+ c2, _ := tr.Dial("udp")
+ c3, _ := tr.Dial("udp")
+
+ tr.Yield(c1)
+ tr.Yield(c2)
+ tr.Yield(c3)
+
+ if x := tr.Len(); x != 3 {
+ t.Errorf("Expected cache size to be 3, got %d", x)
+ }
+
+ tr.Dial("udp")
+ if x := tr.Len(); x != 2 {
+ t.Errorf("Expected cache size to be 2, got %d", x)
+ }
+
+ tr.Dial("udp")
+ if x := tr.Len(); x != 1 {
+ t.Errorf("Expected cache size to be 2, got %d", x)
+ }
+}