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:
Miek Gieben
2016-08-14 12:57:49 -06:00
committed by GitHub
parent 6d3f9d2193
commit 34ffb2b314
10 changed files with 62 additions and 90 deletions

View File

@@ -3,12 +3,13 @@ package test
import (
"net"
"sync"
"testing"
"time"
"github.com/miekg/dns"
)
func TCPServer(laddr string) (*dns.Server, string, error) {
func TCPServer(t *testing.T, laddr string) (*dns.Server, string, error) {
l, err := net.Listen("tcp", laddr)
if err != nil {
return nil, "", err
@@ -18,7 +19,7 @@ func TCPServer(laddr string) (*dns.Server, string, error) {
waitLock := sync.Mutex{}
waitLock.Lock()
server.NotifyStartedFunc = waitLock.Unlock
server.NotifyStartedFunc = func() { t.Logf("started TCP server on %s", l.Addr()); waitLock.Unlock() }
go func() {
server.ActivateAndServe()
@@ -29,25 +30,22 @@ func TCPServer(laddr string) (*dns.Server, string, error) {
return server, l.Addr().String(), nil
}
func UDPServer(laddr string) (*dns.Server, string, chan bool, error) {
func UDPServer(t *testing.T, laddr string) (*dns.Server, string, error) {
pc, err := net.ListenPacket("udp", laddr)
if err != nil {
return nil, "", nil, err
return nil, "", err
}
server := &dns.Server{PacketConn: pc, ReadTimeout: time.Hour, WriteTimeout: time.Hour}
waitLock := sync.Mutex{}
waitLock.Lock()
server.NotifyStartedFunc = waitLock.Unlock
stop := make(chan bool)
server.NotifyStartedFunc = func() { t.Logf("started UDP server on %s", pc.LocalAddr()); waitLock.Unlock() }
go func() {
server.ActivateAndServe()
close(stop)
pc.Close()
}()
waitLock.Lock()
return server, pc.LocalAddr().String(), stop, nil
return server, pc.LocalAddr().String(), nil
}