aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-01-11 21:23:57 +0000
committerGravatar GitHub <noreply@github.com> 2017-01-11 21:23:57 +0000
commit0c3ad499d87b4ee4e43a49ac8c8102e6369d7e19 (patch)
treee0952593e0a6ac14ff236e4f37ff82476fb38a2f /test
parent0ee88d300794a9c77d96c57097b72743758e8bd4 (diff)
downloadcoredns-0c3ad499d87b4ee4e43a49ac8c8102e6369d7e19.tar.gz
coredns-0c3ad499d87b4ee4e43a49ac8c8102e6369d7e19.tar.zst
coredns-0c3ad499d87b4ee4e43a49ac8c8102e6369d7e19.zip
middleware/proxy: add read/writeDeadline (#477)
Add deadline to break the connection. We use the default of 5 seconds. After this the backend is marked unhealthy and not used for some time. Fixes #467
Diffstat (limited to 'test')
-rw-r--r--test/proxy_health_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/proxy_health_test.go b/test/proxy_health_test.go
new file mode 100644
index 000000000..143846688
--- /dev/null
+++ b/test/proxy_health_test.go
@@ -0,0 +1,43 @@
+package test
+
+import (
+ "io/ioutil"
+ "log"
+ "testing"
+
+ "github.com/miekg/coredns/middleware/proxy"
+ "github.com/miekg/coredns/middleware/test"
+ "github.com/miekg/coredns/request"
+
+ "github.com/miekg/dns"
+)
+
+func TestProxyErratic(t *testing.T) {
+ log.SetOutput(ioutil.Discard)
+
+ corefile := `example.org:0 {
+ erratic {
+ drop 2
+ }
+ }
+`
+
+ backend, err := CoreDNSServer(corefile)
+ if err != nil {
+ t.Fatalf("Could not get CoreDNS serving instance: %s", err)
+ }
+
+ udp, _ := CoreDNSServerPorts(backend, 0)
+ if udp == "" {
+ t.Fatalf("Could not get UDP listening port")
+ }
+ defer backend.Stop()
+
+ p := proxy.New([]string{udp})
+ state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
+
+ // We do one lookup that should not time out.
+ // After this the backend is marked unhealthy anyway. So basically this
+ // tests that it times out.
+ p.Lookup(state, "example.org.", dns.TypeA)
+}