mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
plugin/forward: configurable domain support for healthcheck (#5281)
* plugin/forward: configurable domain support for healthcheck Signed-off-by: hansedong <admin@yinxiaoluo.com>
This commit is contained in:
@@ -242,3 +242,42 @@ func TestHealthNoMaxFails(t *testing.T) {
|
||||
t.Errorf("Expected number of health checks to be %d, got %d", 0, i1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthDomain(t *testing.T) {
|
||||
hcReadTimeout = 10 * time.Millisecond
|
||||
readTimeout = 10 * time.Millisecond
|
||||
defaultTimeout = 10 * time.Millisecond
|
||||
hcWriteTimeout = 10 * time.Millisecond
|
||||
hcDomain := "example.org."
|
||||
i := uint32(0)
|
||||
q := uint32(0)
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
if atomic.LoadUint32(&q) == 0 { //drop the first query to trigger health-checking
|
||||
atomic.AddUint32(&q, 1)
|
||||
return
|
||||
}
|
||||
if r.Question[0].Name == hcDomain && r.RecursionDesired == true {
|
||||
atomic.AddUint32(&i, 1)
|
||||
}
|
||||
ret := new(dns.Msg)
|
||||
ret.SetReply(r)
|
||||
w.WriteMsg(ret)
|
||||
})
|
||||
defer s.Close()
|
||||
p := NewProxy(s.Addr, transport.DNS)
|
||||
p.health.SetDomain(hcDomain)
|
||||
f := New()
|
||||
f.SetProxy(p)
|
||||
defer f.OnShutdown()
|
||||
|
||||
req := new(dns.Msg)
|
||||
req.SetQuestion(".", dns.TypeNS)
|
||||
|
||||
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
||||
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
i1 := atomic.LoadUint32(&i)
|
||||
if i1 != 1 {
|
||||
t.Errorf("Expected number of health checks with Domain==%s to be %d, got %d", hcDomain, 1, i1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user