refactor(netx/dialer): hide implementation complexity (#372)
* refactor(netx/dialer): hide implementation complexity This follows the blueprint of `module.Config` and `nodule.New` described at https://github.com/ooni/probe/issues/1591. * fix: ndt7 bug where we were not using the right resolver * fix(legacy/netx): clarify irrelevant implementation change * fix: improve comments * fix(hhfm): do not use dialer.New b/c it breaks it Unclear to me why this is happening. Still, improve upon the previous situation by adding a timeout. It does not seem a priority to look into this issue now.
This commit is contained in:
parent
b7a6dbe47b
commit
06ee0e55a9
30 changed files with 312 additions and 517 deletions
|
|
@ -1,4 +1,4 @@
|
|||
package dialer_test
|
||||
package dialer
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
@ -10,14 +10,13 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex"
|
||||
)
|
||||
|
||||
func dorequest(ctx context.Context, url string) error {
|
||||
txp := http.DefaultTransport.(*http.Transport).Clone()
|
||||
defer txp.CloseIdleConnections()
|
||||
dialer := dialer.ByteCounterDialer{Dialer: new(net.Dialer)}
|
||||
dialer := &byteCounterDialer{Dialer: new(net.Dialer)}
|
||||
txp.DialContext = dialer.DialContext
|
||||
client := &http.Client{Transport: txp}
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "http://www.google.com", nil)
|
||||
|
|
@ -40,12 +39,12 @@ func TestByteCounterNormalUsage(t *testing.T) {
|
|||
}
|
||||
sess := bytecounter.New()
|
||||
ctx := context.Background()
|
||||
ctx = dialer.WithSessionByteCounter(ctx, sess)
|
||||
ctx = WithSessionByteCounter(ctx, sess)
|
||||
if err := dorequest(ctx, "http://www.google.com"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exp := bytecounter.New()
|
||||
ctx = dialer.WithExperimentByteCounter(ctx, exp)
|
||||
ctx = WithExperimentByteCounter(ctx, exp)
|
||||
if err := dorequest(ctx, "http://facebook.com"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -71,7 +70,7 @@ func TestByteCounterNoHandlers(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestByteCounterConnectFailure(t *testing.T) {
|
||||
dialer := dialer.ByteCounterDialer{Dialer: mockablex.Dialer{
|
||||
dialer := &byteCounterDialer{Dialer: mockablex.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
|
||||
return nil, io.EOF
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue