summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/miekg/dns/client_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/miekg/dns/client_test.go')
-rw-r--r--vendor/github.com/miekg/dns/client_test.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/vendor/github.com/miekg/dns/client_test.go b/vendor/github.com/miekg/dns/client_test.go
index dee585f36..73083dbaf 100644
--- a/vendor/github.com/miekg/dns/client_test.go
+++ b/vendor/github.com/miekg/dns/client_test.go
@@ -1,6 +1,7 @@
package dns
import (
+ "context"
"crypto/tls"
"fmt"
"net"
@@ -249,6 +250,9 @@ func TestClientConn(t *testing.T) {
t.Errorf("failed to exchange: %v", err)
}
r, err := cn.ReadMsg()
+ if err != nil {
+ t.Errorf("failed to get a valid answer: %v", err)
+ }
if r == nil || r.Rcode != RcodeSuccess {
t.Errorf("failed to get an valid answer\n%v", r)
}
@@ -262,6 +266,9 @@ func TestClientConn(t *testing.T) {
if buf == nil {
t.Errorf("failed to get an valid answer\n%v", r)
}
+ if err != nil {
+ t.Errorf("failed to get a valid answer: %v", err)
+ }
if int(h.Bits&0xF) != RcodeSuccess {
t.Errorf("failed to get an valid answer in ReadMsgHeader\n%v", r)
}
@@ -423,7 +430,7 @@ func TestTimeout(t *testing.T) {
// Use a channel + timeout to ensure we don't get stuck if the
// Client Timeout is not working properly
- done := make(chan struct{})
+ done := make(chan struct{}, 2)
timeout := time.Millisecond
allowable := timeout + (10 * time.Millisecond)
@@ -435,14 +442,28 @@ func TestTimeout(t *testing.T) {
c := &Client{Timeout: timeout}
_, _, err := c.Exchange(m, addrstr)
if err == nil {
- t.Error("no timeout using Client")
+ t.Error("no timeout using Client.Exchange")
+ }
+ done <- struct{}{}
+ }()
+
+ go func() {
+ ctx, cancel := context.WithTimeout(context.Background(), timeout)
+ defer cancel()
+ c := &Client{}
+ _, _, err := c.ExchangeContext(ctx, m, addrstr)
+ if err == nil {
+ t.Error("no timeout using Client.ExchangeContext")
}
done <- struct{}{}
}()
- select {
- case <-done:
- case <-time.After(abortAfter):
+ // Wait for both the Exchange and ExchangeContext tests to be done.
+ for i := 0; i < 2; i++ {
+ select {
+ case <-done:
+ case <-time.After(abortAfter):
+ }
}
length := time.Since(start)