mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
plugin/forward: Allow Proxy to be used outside of forward plugin. (#5951)
* plugin/forward: Move Proxy into pkg/plugin/proxy, to allow forward.Proxy to be used outside of forward plugin. Signed-off-by: Patrick Downey <patrick.downey@dioadconsulting.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||
"github.com/coredns/coredns/plugin/pkg/proxy"
|
||||
"github.com/coredns/coredns/plugin/pkg/transport"
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
|
||||
@@ -14,9 +15,6 @@ import (
|
||||
)
|
||||
|
||||
func TestHealth(t *testing.T) {
|
||||
hcReadTimeout = 10 * time.Millisecond
|
||||
hcWriteTimeout = 10 * time.Millisecond
|
||||
readTimeout = 10 * time.Millisecond
|
||||
defaultTimeout = 10 * time.Millisecond
|
||||
|
||||
i := uint32(0)
|
||||
@@ -35,7 +33,9 @@ func TestHealth(t *testing.T) {
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
p := NewProxy(s.Addr, transport.DNS)
|
||||
p := proxy.NewProxy(s.Addr, transport.DNS)
|
||||
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
||||
f := New()
|
||||
f.SetProxy(p)
|
||||
defer f.OnShutdown()
|
||||
@@ -53,9 +53,6 @@ func TestHealth(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHealthTCP(t *testing.T) {
|
||||
hcReadTimeout = 10 * time.Millisecond
|
||||
hcWriteTimeout = 10 * time.Millisecond
|
||||
readTimeout = 10 * time.Millisecond
|
||||
defaultTimeout = 10 * time.Millisecond
|
||||
|
||||
i := uint32(0)
|
||||
@@ -74,8 +71,10 @@ func TestHealthTCP(t *testing.T) {
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
p := NewProxy(s.Addr, transport.DNS)
|
||||
p.health.SetTCPTransport()
|
||||
p := proxy.NewProxy(s.Addr, transport.DNS)
|
||||
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetTCPTransport()
|
||||
f := New()
|
||||
f.SetProxy(p)
|
||||
defer f.OnShutdown()
|
||||
@@ -93,10 +92,7 @@ func TestHealthTCP(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHealthNoRecursion(t *testing.T) {
|
||||
hcReadTimeout = 10 * time.Millisecond
|
||||
readTimeout = 10 * time.Millisecond
|
||||
defaultTimeout = 10 * time.Millisecond
|
||||
hcWriteTimeout = 10 * time.Millisecond
|
||||
|
||||
i := uint32(0)
|
||||
q := uint32(0)
|
||||
@@ -114,8 +110,10 @@ func TestHealthNoRecursion(t *testing.T) {
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
p := NewProxy(s.Addr, transport.DNS)
|
||||
p.health.SetRecursionDesired(false)
|
||||
p := proxy.NewProxy(s.Addr, transport.DNS)
|
||||
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetRecursionDesired(false)
|
||||
f := New()
|
||||
f.SetProxy(p)
|
||||
defer f.OnShutdown()
|
||||
@@ -133,9 +131,6 @@ func TestHealthNoRecursion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHealthTimeout(t *testing.T) {
|
||||
hcReadTimeout = 10 * time.Millisecond
|
||||
hcWriteTimeout = 10 * time.Millisecond
|
||||
readTimeout = 10 * time.Millisecond
|
||||
defaultTimeout = 10 * time.Millisecond
|
||||
|
||||
i := uint32(0)
|
||||
@@ -159,7 +154,9 @@ func TestHealthTimeout(t *testing.T) {
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
p := NewProxy(s.Addr, transport.DNS)
|
||||
p := proxy.NewProxy(s.Addr, transport.DNS)
|
||||
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
||||
f := New()
|
||||
f.SetProxy(p)
|
||||
defer f.OnShutdown()
|
||||
@@ -177,19 +174,20 @@ func TestHealthTimeout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHealthMaxFails(t *testing.T) {
|
||||
hcReadTimeout = 10 * time.Millisecond
|
||||
hcWriteTimeout = 10 * time.Millisecond
|
||||
readTimeout = 10 * time.Millisecond
|
||||
defaultTimeout = 10 * time.Millisecond
|
||||
hcInterval = 10 * time.Millisecond
|
||||
//,hcInterval = 10 * time.Millisecond
|
||||
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
// timeout
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
p := NewProxy(s.Addr, transport.DNS)
|
||||
p := proxy.NewProxy(s.Addr, transport.DNS)
|
||||
p.SetReadTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
||||
f := New()
|
||||
f.hcInterval = 10 * time.Millisecond
|
||||
f.maxfails = 2
|
||||
f.SetProxy(p)
|
||||
defer f.OnShutdown()
|
||||
@@ -200,18 +198,14 @@ func TestHealthMaxFails(t *testing.T) {
|
||||
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
fails := atomic.LoadUint32(&p.fails)
|
||||
fails := p.Fails()
|
||||
if !p.Down(f.maxfails) {
|
||||
t.Errorf("Expected Proxy fails to be greater than %d, got %d", f.maxfails, fails)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthNoMaxFails(t *testing.T) {
|
||||
hcReadTimeout = 10 * time.Millisecond
|
||||
hcWriteTimeout = 10 * time.Millisecond
|
||||
readTimeout = 10 * time.Millisecond
|
||||
defaultTimeout = 10 * time.Millisecond
|
||||
hcInterval = 10 * time.Millisecond
|
||||
|
||||
i := uint32(0)
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
@@ -225,7 +219,9 @@ func TestHealthNoMaxFails(t *testing.T) {
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
p := NewProxy(s.Addr, transport.DNS)
|
||||
p := proxy.NewProxy(s.Addr, transport.DNS)
|
||||
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
||||
f := New()
|
||||
f.maxfails = 0
|
||||
f.SetProxy(p)
|
||||
@@ -244,10 +240,8 @@ func TestHealthNoMaxFails(t *testing.T) {
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -264,8 +258,10 @@ func TestHealthDomain(t *testing.T) {
|
||||
w.WriteMsg(ret)
|
||||
})
|
||||
defer s.Close()
|
||||
p := NewProxy(s.Addr, transport.DNS)
|
||||
p.health.SetDomain(hcDomain)
|
||||
p := proxy.NewProxy(s.Addr, transport.DNS)
|
||||
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
||||
p.GetHealthchecker().SetDomain(hcDomain)
|
||||
f := New()
|
||||
f.SetProxy(p)
|
||||
defer f.OnShutdown()
|
||||
|
||||
Reference in New Issue
Block a user