Skip to content

Commit

Permalink
Resolve feedbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
and1truong committed Feb 28, 2024
1 parent 40a85c3 commit c9ea67f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
18 changes: 3 additions & 15 deletions internal/resolver/dns/dns_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ func (s) TestResolveTimeout(t *testing.T) {
overrideResolveTimeoutDuration(t, timeoutDur)

// context with a bit larger
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()

// We are trying to resolve hostname which takes infinity time to resolve.
Expand All @@ -1249,23 +1249,11 @@ func (s) TestResolveTimeout(t *testing.T) {

// block testNetResolver.testNetResolver until timeout
_ = tr.lookupHostCh.SendContext(ctx, nil)
_, stateCh, errCh := buildResolverWithTestClientConn(t, target)

// wait until timeout
<-ctx.Done()

// unblock testNetResolver.lookupHostCh channel
if _, ok := tr.lookupHostCh.ReceiveOrFail(); !ok {
t.Fatalf("failed for lookup() call.")
}

_, _, errCh := buildResolverWithTestClientConn(t, target)
select {

Check failure on line 1253 in internal/resolver/dns/dns_resolver_test.go

View workflow job for this annotation

GitHub Actions / tests (vet, 1.22)

should use a simple channel send/receive instead of select with a single case (S1000)
case err := <-errCh:
if err == nil || !strings.Contains(err.Error(), "hostLookup timeout") {
if err == nil || !strings.Contains(err.Error(), "context deadline exceeded") {
t.Fatalf(`We expect to see timed out error`)
}

case <-stateCh:
t.Fatalf(`We expect to see timed out error`)
}
}
7 changes: 1 addition & 6 deletions internal/resolver/dns/fake_net_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ type testNetResolver struct {
func (tr *testNetResolver) LookupHost(ctx context.Context, host string) ([]string, error) {
if tr.lookupHostCh != nil {
if err := tr.lookupHostCh.SendContext(ctx, nil); nil != err {
return nil, &net.DNSError{
Err: "hostLookup timeout",
Name: host,
Server: "fake",
IsTemporary: true,
}
return nil, err
}
}

Expand Down
2 changes: 1 addition & 1 deletion resolver/dns/dns_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
// It must be called only at application startup, before any gRPC calls are made.
// Modifying this value after initialization is not thread-safe.
//
// The default value is 10 seconds. Setting the timeout too low may result
// The default value is 30 seconds. Setting the timeout too low may result
// in premature timeouts during resolution, while setting it too high may
// lead to unnecessary delays in service discovery. Choose a value appropriate
// for your specific needs and network environment.
Expand Down

0 comments on commit c9ea67f

Please sign in to comment.