fix TestNewServer() hanging (#1786)

This commit is contained in:
Ruslan Drozhdzh 2018-05-08 20:35:47 +03:00 committed by Miek Gieben
parent 643550eabe
commit 0455febc34
2 changed files with 18 additions and 2 deletions

View file

@ -23,8 +23,15 @@ func NewServer(f dns.HandlerFunc) *Server {
ch1 := make(chan bool)
ch2 := make(chan bool)
p, _ := net.ListenPacket("udp", ":0")
l, _ := net.Listen("tcp", p.LocalAddr().String())
l, _ := net.Listen("tcp", ":0")
if l == nil {
return nil
}
p, _ := net.ListenPacket("udp", l.Addr().String())
if p == nil {
l.Close()
return nil // yes, this may crash some test, but this is better than hanging
}
s1 := &dns.Server{PacketConn: p}
s2 := &dns.Server{Listener: l}