Fixed client tests and removed TODO about timeouts
This commit is contained in:
parent
87f8764f43
commit
e7a401841e
|
@ -133,4 +133,3 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
|
||||||
* CAA parsing is broken;
|
* CAA parsing is broken;
|
||||||
* Replies with TC bit are not parsed to the end.
|
* Replies with TC bit are not parsed to the end.
|
||||||
* SIG(0)
|
* SIG(0)
|
||||||
* Make tests run faster by removing the time.Sleep()s
|
|
||||||
|
|
|
@ -9,27 +9,25 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestServer(t *testing.T) {
|
func TestClientSync(t *testing.T) {
|
||||||
// Defined in server_test.go
|
|
||||||
HandleFunc("miek.nl.", HelloServer)
|
HandleFunc("miek.nl.", HelloServer)
|
||||||
HandleFunc("example.com.", AnotherHelloServer)
|
HandleFunc("example.com.", AnotherHelloServer)
|
||||||
go func() {
|
|
||||||
err := ListenAndServe(":8063", "udp", nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Log("ListenAndServe: ", err.Error())
|
|
||||||
t.Fatal()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
time.Sleep(4e8)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestClientSync(t *testing.T) {
|
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to run test server: %s", err)
|
||||||
|
}
|
||||||
|
defer s.Shutdown()
|
||||||
|
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
m.SetQuestion("miek.nl.", TypeSOA)
|
m.SetQuestion("miek.nl.", TypeSOA)
|
||||||
|
|
||||||
c := new(Client)
|
c := new(Client)
|
||||||
r, _, _ := c.Exchange(m, "127.0.0.1:6053")
|
r, _, e := c.Exchange(m, addrstr)
|
||||||
|
if e != nil {
|
||||||
|
t.Logf("failed to exchange: %s", e.Error())
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
if r != nil && r.Rcode != RcodeSuccess {
|
if r != nil && r.Rcode != RcodeSuccess {
|
||||||
t.Log("failed to get an valid answer")
|
t.Log("failed to get an valid answer")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -38,13 +36,26 @@ func TestClientSync(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientEDNS0(t *testing.T) {
|
func TestClientEDNS0(t *testing.T) {
|
||||||
|
HandleFunc("miek.nl.", HelloServer)
|
||||||
|
HandleFunc("example.com.", AnotherHelloServer)
|
||||||
|
|
||||||
|
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to run test server: %s", err)
|
||||||
|
}
|
||||||
|
defer s.Shutdown()
|
||||||
|
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
m.SetQuestion("miek.nl.", TypeDNSKEY)
|
m.SetQuestion("miek.nl.", TypeDNSKEY)
|
||||||
|
|
||||||
m.SetEdns0(2048, true)
|
m.SetEdns0(2048, true)
|
||||||
|
|
||||||
c := new(Client)
|
c := new(Client)
|
||||||
r, _, _ := c.Exchange(m, "127.0.0.1:6053")
|
r, _, e := c.Exchange(m, addrstr)
|
||||||
|
if e != nil {
|
||||||
|
t.Logf("failed to exchange: %s", e.Error())
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
if r != nil && r.Rcode != RcodeSuccess {
|
if r != nil && r.Rcode != RcodeSuccess {
|
||||||
t.Log("failed to get an valid answer")
|
t.Log("failed to get an valid answer")
|
||||||
|
@ -54,6 +65,15 @@ func TestClientEDNS0(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSingleSingleInflight(t *testing.T) {
|
func TestSingleSingleInflight(t *testing.T) {
|
||||||
|
HandleFunc("miek.nl.", HelloServer)
|
||||||
|
HandleFunc("example.com.", AnotherHelloServer)
|
||||||
|
|
||||||
|
s, addrstr, err := RunLocalUDPServer("127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to run test server: %s", err)
|
||||||
|
}
|
||||||
|
defer s.Shutdown()
|
||||||
|
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
m.SetQuestion("miek.nl.", TypeDNSKEY)
|
m.SetQuestion("miek.nl.", TypeDNSKEY)
|
||||||
|
|
||||||
|
@ -63,7 +83,7 @@ func TestSingleSingleInflight(t *testing.T) {
|
||||||
ch := make(chan time.Duration)
|
ch := make(chan time.Duration)
|
||||||
for i := 0; i < nr; i++ {
|
for i := 0; i < nr; i++ {
|
||||||
go func() {
|
go func() {
|
||||||
_, rtt, _ := c.Exchange(m, "127.0.0.1:6053")
|
_, rtt, _ := c.Exchange(m, addrstr)
|
||||||
ch <- rtt
|
ch <- rtt
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue