refactor: start refactoring session resolver (#807)
This diff addresses the following points of https://github.com/ooni/probe/issues/2135: - [x] the `childResolver` type is useless and we can use `model.Resolver` directly; - [x] we should use `model/mocks` instead of custom fakes; - [x] we should not use `log.Log` rather we should use `model.DiscardLogger`; - [x] make `timeLimitedLookup` easier to test with a `-short` tests; - [x] ensure `timeLimitedLookup` returns as soon as its context expires regardless of the child resolver; Subsequent diffs will address more points mentioned in there.
This commit is contained in:
parent
dea23b49d5
commit
fe29b432e0
8 changed files with 126 additions and 84 deletions
|
|
@ -95,7 +95,7 @@ type Resolver struct {
|
|||
// res maps a URL to a child resolver. We will
|
||||
// construct child resolvers just once and we
|
||||
// will track them into this field.
|
||||
res map[string]childResolver
|
||||
res map[string]model.Resolver
|
||||
}
|
||||
|
||||
// CloseIdleConnections closes the idle connections, if any. This
|
||||
|
|
@ -169,7 +169,7 @@ func (r *Resolver) lookupHost(ctx context.Context, ri *resolverinfo, hostname st
|
|||
ri.Score = 0 // this is a hard error
|
||||
return nil, err
|
||||
}
|
||||
addrs, err := r.timeLimitedLookup(ctx, re, hostname)
|
||||
addrs, err := timeLimitedLookup(ctx, re, hostname)
|
||||
if err == nil {
|
||||
r.logger().Infof("sessionresolver: %s... %v", ri.URL, model.ErrorToStringOrOK(nil))
|
||||
ri.Score = ewma*1.0 + (1-ewma)*ri.Score // increase score
|
||||
|
|
|
|||
Loading…
Reference in a new issue