diff options
Diffstat (limited to 'plugin/forward/health_test.go')
-rw-r--r-- | plugin/forward/health_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/plugin/forward/health_test.go b/plugin/forward/health_test.go index 2d65f4353..9917b3a37 100644 --- a/plugin/forward/health_test.go +++ b/plugin/forward/health_test.go @@ -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) + } +} |