Fix TestStubLookup and TestLookup (#213)
Changes large parts of proxy lookup mechanism. The duplicate zone checking erroneous added a nameserver for each zone we are auth. for, creating to many backend hosts. So even when a host was determined do be Down() we still got an (identical) new one from the list. The Down() and failure checking for upstream hosts had data race in the uh.Fails check - we now use atomic.LoadInt32 for that. Use and debug the test/server.go test servers implementation in the TestStubLookup test to prevent going out to the internet. Also delete the stub cycle test. That test was wrong and did not test what it needed to be testing. Deleted for now.
This commit is contained in:
parent
6d3f9d2193
commit
34ffb2b314
10 changed files with 62 additions and 90 deletions
|
@ -3,7 +3,9 @@
|
|||
package etcd
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sort"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
|
@ -13,11 +15,37 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func fakeStubServerExampleNet(t *testing.T) (*dns.Server, string) {
|
||||
server, addr, err := test.UDPServer(t, "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a UDP server: %s", err)
|
||||
}
|
||||
// add handler for example.net
|
||||
dns.HandleFunc("example.net.", func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
t.Logf("writing response for example.net.")
|
||||
m := new(dns.Msg)
|
||||
m.SetReply(r)
|
||||
m.Answer = []dns.RR{test.A("example.net. 86400 IN A 93.184.216.34")}
|
||||
w.WriteMsg(m)
|
||||
})
|
||||
|
||||
return server, addr
|
||||
}
|
||||
|
||||
func TestStubLookup(t *testing.T) {
|
||||
server, addr := fakeStubServerExampleNet(t)
|
||||
defer server.Shutdown()
|
||||
|
||||
host, p, _ := net.SplitHostPort(addr)
|
||||
port, _ := strconv.Atoi(p)
|
||||
exampleNetStub := &msg.Service{Host: host, Port: port, Key: "a.example.net.stub.dns.skydns.test."}
|
||||
servicesStub = append(servicesStub, exampleNetStub)
|
||||
|
||||
for _, serv := range servicesStub {
|
||||
set(t, etc, serv.Key, 0, serv)
|
||||
defer delete(t, etc, serv.Key)
|
||||
}
|
||||
|
||||
etc.updateStubZones()
|
||||
defer func() { etc.Stubmap = nil }()
|
||||
|
||||
|
@ -26,13 +54,13 @@ func TestStubLookup(t *testing.T) {
|
|||
|
||||
rec := middleware.NewResponseRecorder(&test.ResponseWriter{})
|
||||
_, err := etc.ServeDNS(ctxt, rec, m)
|
||||
if err != nil {
|
||||
if tc.Rcode != dns.RcodeServerFailure {
|
||||
t.Errorf("expected no error, got %v\n", err)
|
||||
}
|
||||
if err != nil && m.Question[0].Name == "example.org." {
|
||||
// This is OK, we expect this backend to *not* work.
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("expected no error, got %v for %s\n", err, m.Question[0].Name)
|
||||
}
|
||||
resp := rec.Msg()
|
||||
if resp == nil {
|
||||
// etcd not running?
|
||||
|
@ -63,8 +91,6 @@ var servicesStub = []*msg.Service{
|
|||
// Two tests, ask a question that should return servfail because remote it no accessible
|
||||
// and one with edns0 option added, that should return refused.
|
||||
{Host: "127.0.0.1", Port: 666, Key: "b.example.org.stub.dns.skydns.test."},
|
||||
// Actual test that goes out to the internet.
|
||||
{Host: "199.43.132.53", Key: "a.example.net.stub.dns.skydns.test."},
|
||||
}
|
||||
|
||||
var dnsTestCasesStub = []test.Case{
|
||||
|
@ -74,23 +100,6 @@ var dnsTestCasesStub = []test.Case{
|
|||
{
|
||||
Qname: "example.net.", Qtype: dns.TypeA,
|
||||
Answer: []dns.RR{test.A("example.net. 86400 IN A 93.184.216.34")},
|
||||
Ns: []dns.RR{
|
||||
test.NS("example.net. 86400 IN NS a.iana-servers.net."),
|
||||
test.NS("example.net. 86400 IN NS b.iana-servers.net."),
|
||||
},
|
||||
Extra: []dns.RR{test.OPT(4096, false)}, // This will have an EDNS0 section, because *we* added our local stub forward to detect loops.
|
||||
},
|
||||
{
|
||||
Qname: "example.net.", Qtype: dns.TypeA, Do: true,
|
||||
Answer: []dns.RR{
|
||||
test.A("example.net. 86400 IN A 93.184.216.34"),
|
||||
test.RRSIG("example.net. 86400 IN RRSIG A 8 2 86400 20160428060557 20160406182909 40948 example.net. Vm+rH5KN"),
|
||||
},
|
||||
Ns: []dns.RR{
|
||||
test.NS("example.net. 86400 IN NS a.iana-servers.net."),
|
||||
test.NS("example.net. 86400 IN NS b.iana-servers.net."),
|
||||
test.RRSIG("example.net. 86400 IN RRSIG NS 8 2 86400 20160428110538 20160407002909 40948 example.net. z74YR2"),
|
||||
},
|
||||
Extra: []dns.RR{test.OPT(4096, true)},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue