Skip to content

Commit

Permalink
Cleaner deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Dec 26, 2023
1 parent f4d461d commit 476ecfe
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions x/connectivity/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ func makeConnectivityError(op string, err error) *ConnectivityError {
// Valid tests will return (*ConnectivityError, nil), where *ConnectivityError will be nil if there's connectivity or
// a structure with details of the error found.
func TestConnectivityWithResolver(ctx context.Context, resolver Resolver, testDomain string) (*ConnectivityError, error) {
if _, ok := ctx.Deadline(); !ok {
deadline, ok := ctx.Deadline()
if !ok {
// Default deadline is 5 seconds.
deadline := time.Now().Add(5 * time.Second)
deadline = time.Now().Add(5 * time.Second)
var cancel context.CancelFunc
ctx, cancel = context.WithDeadline(ctx, deadline)
// Releases the timer.
Expand All @@ -109,9 +110,7 @@ func TestConnectivityWithResolver(ctx context.Context, resolver Resolver, testDo
return makeConnectivityError("connect", err), nil
}
defer dnsConn.Close()
if deadline, ok := ctx.Deadline(); ok {
dnsConn.SetDeadline(deadline)
}
dnsConn.SetDeadline(deadline)

var dnsRequest dns.Msg
dnsRequest.SetQuestion(dns.Fqdn(testDomain), dns.TypeA)
Expand Down

0 comments on commit 476ecfe

Please sign in to comment.