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
@@ -16,7 +16,7 @@ import (
const (
testName = "psiphon"
testVersion = "0.5.1"
testVersion = "0.6.0"
)
// Config contains the experiment's configuration.
@@ -92,14 +92,14 @@ func (m *Measurer) Run(
if m.BeforeGetHook != nil {
m.BeforeGetHook(g)
}
tk, err := g.Get(ctx)
tk, _ := g.Get(ctx) // ignore error since we have the testkeys and want to submit them
cancel()
wg.Wait()
measurement.TestKeys = &TestKeys{
TestKeys: tk,
MaxRuntime: maxruntime,
}
return err
return nil
}
// NewExperimentMeasurer creates a new ExperimentMeasurer.
@@ -23,7 +23,7 @@ func TestNewExperimentMeasurer(t *testing.T) {
if measurer.ExperimentName() != "psiphon" {
t.Fatal("unexpected name")
}
if measurer.ExperimentVersion() != "0.5.1" {
if measurer.ExperimentVersion() != "0.6.0" {
t.Fatal("unexpected version")
}
}
@@ -35,7 +35,7 @@ func TestRunWithCancelledContext(t *testing.T) {
measurement := new(model.Measurement)
err := measurer.Run(ctx, newfakesession(), measurement,
model.NewPrinterCallbacks(log.Log))
if !errors.Is(err, context.Canceled) {
if !errors.Is(err, nil) { // nil because we want to submit the measurement
t.Fatal("expected another error here")
}
tk := measurement.TestKeys.(*psiphon.TestKeys)
@@ -66,7 +66,7 @@ func TestRunWithCustomInputAndCancelledContext(t *testing.T) {
cancel() // fail immediately
err := measurer.Run(ctx, newfakesession(), measurement,
model.NewPrinterCallbacks(log.Log))
if !errors.Is(err, context.Canceled) {
if !errors.Is(err, nil) { // nil because we want to submit the measurement
t.Fatal("expected another error here")
}
tk := measurement.TestKeys.(*psiphon.TestKeys)
@@ -85,7 +85,7 @@ func TestRunWillPrintSomethingWithCancelledContext(t *testing.T) {
}
observer := observerCallbacks{progress: &atomicx.Int64{}}
err := measurer.Run(ctx, newfakesession(), measurement, observer)
if !errors.Is(err, context.Canceled) {
if !errors.Is(err, nil) { // nil because we want to submit the measurement
t.Fatal("expected another error here")
}
tk := measurement.TestKeys.(*psiphon.TestKeys)