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
+8 -2
View File
@@ -25,7 +25,7 @@ const (
defaultTimeout = 120 * time.Second
magicVersion = "0.008000000"
testName = "dash"
testVersion = "0.12.0"
testVersion = "0.13.0"
totalStep = 15.0
)
@@ -273,7 +273,13 @@ func (m Measurer) Run(
}
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
defer cancel()
return r.do(ctx)
// Implementation note: we ignore the return value of r.do rather than
// returning it to the caller. We do that because returning an error means
// the measurement failed for some fundamental reason (e.g., the input
// is an URL that you cannot parse). For DASH, this case will never happen
// because there is no input, so always returning nil is fine here.
_ = r.do(ctx)
return nil
}
// NewExperimentMeasurer creates a new ExperimentMeasurer.
+4 -2
View File
@@ -261,7 +261,7 @@ func TestNewExperimentMeasurer(t *testing.T) {
if measurer.ExperimentName() != "dash" {
t.Fatal("unexpected name")
}
if measurer.ExperimentVersion() != "0.12.0" {
if measurer.ExperimentVersion() != "0.13.0" {
t.Fatal("unexpected version")
}
}
@@ -280,7 +280,9 @@ func TestMeasureWithCancelledContext(t *testing.T) {
measurement,
model.NewPrinterCallbacks(log.Log),
)
if !errors.Is(err, context.Canceled) {
// See corresponding comment in Measurer.Run implementation to
// understand why here it's correct to return nil.
if !errors.Is(err, nil) {
t.Fatal("unexpected error value")
}
sk, err := m.GetSummaryKeys(measurement)
+4
View File
@@ -0,0 +1,4 @@
// Package dash implements the DASH network experiment.
//
// Spec: https://github.com/ooni/spec/blob/master/nettests/ts-021-dash.md
package dash