mirror of
https://github.com/coredns/coredns.git
synced 2025-11-12 15:02:17 -05:00
plugin/forward: add query timeout (#1665)
This commit is contained in:
committed by
Miek Gieben
parent
ccfe691b95
commit
a0f294e550
@@ -45,6 +45,7 @@ func TestHealth(t *testing.T) {
|
||||
func TestHealthTimeout(t *testing.T) {
|
||||
const expected = 1
|
||||
i := uint32(0)
|
||||
q := uint32(0)
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
if r.Question[0].Name == "." {
|
||||
// health check, answer
|
||||
@@ -52,8 +53,15 @@ func TestHealthTimeout(t *testing.T) {
|
||||
ret := new(dns.Msg)
|
||||
ret.SetReply(r)
|
||||
w.WriteMsg(ret)
|
||||
return
|
||||
}
|
||||
// not a health check, do a timeout
|
||||
if atomic.LoadUint32(&q) == 0 { //drop only first query
|
||||
atomic.AddUint32(&q, 1)
|
||||
return
|
||||
}
|
||||
ret := new(dns.Msg)
|
||||
ret.SetReply(r)
|
||||
w.WriteMsg(ret)
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
@@ -77,6 +85,7 @@ func TestHealthTimeout(t *testing.T) {
|
||||
func TestHealthFailTwice(t *testing.T) {
|
||||
const expected = 2
|
||||
i := uint32(0)
|
||||
q := uint32(0)
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
if r.Question[0].Name == "." {
|
||||
atomic.AddUint32(&i, 1)
|
||||
@@ -88,7 +97,15 @@ func TestHealthFailTwice(t *testing.T) {
|
||||
ret := new(dns.Msg)
|
||||
ret.SetReply(r)
|
||||
w.WriteMsg(ret)
|
||||
return
|
||||
}
|
||||
if atomic.LoadUint32(&q) == 0 { //drop only first query
|
||||
atomic.AddUint32(&q, 1)
|
||||
return
|
||||
}
|
||||
ret := new(dns.Msg)
|
||||
ret.SetReply(r)
|
||||
w.WriteMsg(ret)
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
@@ -110,10 +127,39 @@ func TestHealthFailTwice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHealthMaxFails(t *testing.T) {
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
// timeout
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
p := NewProxy(s.Addr, nil /* no TLS */)
|
||||
f := New()
|
||||
f.maxfails = 2
|
||||
f.SetProxy(p)
|
||||
defer f.Close()
|
||||
|
||||
req := new(dns.Msg)
|
||||
req.SetQuestion("example.org.", dns.TypeA)
|
||||
|
||||
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
if !p.Down(f.maxfails) {
|
||||
t.Errorf("Expected Proxy fails to be greater than %d, got %d", f.maxfails, p.fails)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthNoMaxFails(t *testing.T) {
|
||||
const expected = 0
|
||||
i := uint32(0)
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
// timeout
|
||||
if r.Question[0].Name == "." {
|
||||
// health check, answer
|
||||
atomic.AddUint32(&i, 1)
|
||||
ret := new(dns.Msg)
|
||||
ret.SetReply(r)
|
||||
w.WriteMsg(ret)
|
||||
}
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user