fix: ensure experiments return nil when we want to submit (#654)

Since https://github.com/ooni/probe-cli/pull/527, if an experiment
returns an error, the corresponding measurement is not submitted since
the semantics of returning an error is that something fundamental
went wrong (e.g., we could not parse the input URL).

This diff ensures that all experiments only return and error when
something fundamental was wrong and return nil otherwise.

Reference issue: https://github.com/ooni/probe/issues/1808.
This commit is contained in:
Simone Basso
2022-01-07 13:17:20 +01:00
committed by GitHub
parent 60a3c372f5
commit 99ec7ffca9
27 changed files with 132 additions and 66 deletions
+7
View File
@@ -257,6 +257,13 @@ func NewHTTPTransportStdlib(logger model.DebugLogger) model.HTTPTransport {
return NewHTTPTransport(logger, dialer, tlsDialer)
}
// NewHTTPClientStdlib creates a new HTTPClient that uses the
// standard library for TLS and DNS resolutions.
func NewHTTPClientStdlib(logger model.DebugLogger) model.HTTPClient {
txp := NewHTTPTransportStdlib(logger)
return WrapHTTPClient(&http.Client{Transport: txp})
}
// WrapHTTPClient wraps an HTTP client to add error wrapping capabilities.
func WrapHTTPClient(clnt model.HTTPClient) model.HTTPClient {
return &httpClientErrWrapper{clnt}
+13
View File
@@ -13,6 +13,7 @@ import (
"github.com/apex/log"
oohttp "github.com/ooni/oohttp"
"github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
@@ -500,6 +501,18 @@ func TestHTTPClientErrWrapper(t *testing.T) {
})
}
func TestNewHTTPClientStdlib(t *testing.T) {
clnt := NewHTTPClientStdlib(model.DiscardLogger)
ewc, ok := clnt.(*httpClientErrWrapper)
if !ok {
t.Fatal("expected *httpClientErrWrapper")
}
_, ok = ewc.HTTPClient.(*http.Client)
if !ok {
t.Fatal("expected *http.Client")
}
}
func TestWrapHTTPClient(t *testing.T) {
origClient := &http.Client{}
wrapped := WrapHTTPClient(origClient)