Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Oct 9, 2023
1 parent aaf4802 commit 3540eee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/engineresolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (r *Resolver) LookupHost(ctx context.Context, hostname string) ([]string, e
//
// See https://github.com/ooni/probe/issues/2544
if err := ctx.Err(); err != nil {
me.Add(err)
me.Add(newErrWrapper(err, e.URL))
continue
}

Expand Down
13 changes: 10 additions & 3 deletions internal/engineresolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ func TestTypicalUsageWithFailure(t *testing.T) {
t.Fatal("cannot convert error")
}
for _, child := range me.Children {

// net.DNSError does not include the underlying error
// but just a string representing the error. This
// means that we need to go down hunting what's the
// real error that occurred and use more verbose code.
{
var ew *errWrapper
if !errors.As(child, &ew) {
t.Fatal("not an instance of errwrapper")
t.Fatalf("not an instance of errwrapper: '%v' [%T]", child, child)
}
var de *net.DNSError
if errors.As(ew, &de) {
Expand All @@ -64,6 +65,7 @@ func TestTypicalUsageWithFailure(t *testing.T) {
continue
}
}

// otherwise just unwrap and check whether it's
// a real context.Canceled error.
if !errors.Is(child, context.Canceled) {
Expand All @@ -73,9 +75,14 @@ func TestTypicalUsageWithFailure(t *testing.T) {
if addrs != nil {
t.Fatal("expected nil here")
}
if len(reso.res) < 1 {
t.Fatal("expected to see some resolvers here")

// since https://github.com/ooni/probe-cli/pull/1351 we avoid
// constructing any resolver if we start running with a canceled context
// because of https://github.com/ooni/probe/issues/2544
if len(reso.res) != 0 {
t.Fatal("expected to see no resolvers here")
}

reso.CloseIdleConnections()
if len(reso.res) != 0 {
t.Fatal("expected to see no resolvers after CloseIdleConnections")
Expand Down

0 comments on commit 3540eee

Please sign in to comment.