Commit 0455febc authored by Ruslan Drozhdzh's avatar Ruslan Drozhdzh Committed by Miek Gieben

fix TestNewServer() hanging (#1786)

parent 643550ea
...@@ -23,8 +23,15 @@ func NewServer(f dns.HandlerFunc) *Server { ...@@ -23,8 +23,15 @@ func NewServer(f dns.HandlerFunc) *Server {
ch1 := make(chan bool) ch1 := make(chan bool)
ch2 := make(chan bool) ch2 := make(chan bool)
p, _ := net.ListenPacket("udp", ":0") l, _ := net.Listen("tcp", ":0")
l, _ := net.Listen("tcp", p.LocalAddr().String()) 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} s1 := &dns.Server{PacketConn: p}
s2 := &dns.Server{Listener: l} s2 := &dns.Server{Listener: l}
......
...@@ -25,4 +25,13 @@ func TestNewServer(t *testing.T) { ...@@ -25,4 +25,13 @@ func TestNewServer(t *testing.T) {
if ret.Id != m.Id { if ret.Id != m.Id {
t.Fatalf("Msg ID's should match, expected %d, got %d", m.Id, ret.Id) t.Fatalf("Msg ID's should match, expected %d, got %d", m.Id, ret.Id)
} }
c.Net = "udp"
ret, _, err = c.Exchange(m, s.Addr)
if err != nil {
t.Fatalf("Could not send message to dnstest.Server: %s", err)
}
if ret.Id != m.Id {
t.Fatalf("Msg ID's should match, expected %d, got %d", m.Id, ret.Id)
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment