diff options
author | 2018-07-07 10:14:21 +0300 | |
---|---|---|
committer | 2018-07-07 08:14:21 +0100 | |
commit | bc5090123487653ce502d5801007d03dbb6a2ba7 (patch) | |
tree | 942ec6a99c31c2c6b477f7027da108aeafc5c857 /plugin/forward/proxy_test.go | |
parent | 7c41f2ce9f75a20d9bba3ab70b4cb8a133a0756f (diff) | |
download | coredns-bc5090123487653ce502d5801007d03dbb6a2ba7.tar.gz coredns-bc5090123487653ce502d5801007d03dbb6a2ba7.tar.zst coredns-bc5090123487653ce502d5801007d03dbb6a2ba7.zip |
plugin/forward: add prefer_udp option (#1944)
* plugin/forward: add prefer_udp option
* updated according to code review
- fixed linter warning
- removed metric parameter in Proxy.Connect()
Diffstat (limited to 'plugin/forward/proxy_test.go')
-rw-r--r-- | plugin/forward/proxy_test.go | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/plugin/forward/proxy_test.go b/plugin/forward/proxy_test.go index 01e8ef6fd..d68d1def2 100644 --- a/plugin/forward/proxy_test.go +++ b/plugin/forward/proxy_test.go @@ -29,10 +29,10 @@ func TestProxyClose(t *testing.T) { p := NewProxy(s.Addr, nil) p.start(hcInterval) - go func() { p.Connect(ctx, state, false, false) }() - go func() { p.Connect(ctx, state, true, false) }() - go func() { p.Connect(ctx, state, false, false) }() - go func() { p.Connect(ctx, state, true, false) }() + go func() { p.Connect(ctx, state, options{}) }() + go func() { p.Connect(ctx, state, options{forceTCP: true}) }() + go func() { p.Connect(ctx, state, options{}) }() + go func() { p.Connect(ctx, state, options{forceTCP: true}) }() p.close() } @@ -93,3 +93,30 @@ func TestProxyTLSFail(t *testing.T) { t.Fatal("Expected *not* to receive reply, but got one") } } + +func TestProtocolSelection(t *testing.T) { + p := NewProxy("bad_address", nil) + + stateUDP := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)} + stateTCP := request.Request{W: &test.ResponseWriter{TCP: true}, Req: new(dns.Msg)} + ctx := context.TODO() + + go func() { + p.Connect(ctx, stateUDP, options{}) + p.Connect(ctx, stateUDP, options{forceTCP: true}) + p.Connect(ctx, stateUDP, options{preferUDP: true}) + p.Connect(ctx, stateUDP, options{preferUDP: true, forceTCP: true}) + p.Connect(ctx, stateTCP, options{}) + p.Connect(ctx, stateTCP, options{forceTCP: true}) + p.Connect(ctx, stateTCP, options{preferUDP: true}) + p.Connect(ctx, stateTCP, options{preferUDP: true, forceTCP: true}) + }() + + for i, exp := range []string{"udp", "tcp", "udp", "tcp", "tcp", "tcp", "udp", "tcp"} { + proto := <-p.transport.dial + p.transport.ret <- nil + if proto != exp { + t.Errorf("Unexpected protocol in case %d, expected %q, actual %q", i, exp, proto) + } + } +} |