[forwardport] fix(stunreachability): don't emit spurious progress events (#803)

This diff forward ports 4fb5f7de69b900cfc2bd211f723108a67bda350d to master.

See https://github.com/ooni/probe/issues/2058#issuecomment-1145847069

This diff WILL need to be forwardported to master.
This commit is contained in:
Simone Basso 2022-06-06 16:21:17 +02:00 committed by GitHub
parent 504181906a
commit 4cf58380c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -6,7 +6,6 @@ package stunreachability
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"net" "net"
"net/url" "net/url"
"time" "time"
@ -108,9 +107,6 @@ func (tk *TestKeys) run(
measurement *model.Measurement, callbacks model.ExperimentCallbacks, measurement *model.Measurement, callbacks model.ExperimentCallbacks,
endpoint string, endpoint string,
) error { ) error {
callbacks.OnProgress(0, fmt.Sprintf("stunreachability: measuring: %s...", endpoint))
defer callbacks.OnProgress(
1, fmt.Sprintf("stunreachability: measuring: %s... done", endpoint))
tk.Endpoint = endpoint tk.Endpoint = endpoint
saver := new(tracex.Saver) saver := new(tracex.Saver)
begin := time.Now() begin := time.Now()
@ -120,6 +116,7 @@ func (tk *TestKeys) run(
ReadWriteSaver: saver, ReadWriteSaver: saver,
Saver: saver, Saver: saver,
}), endpoint) }), endpoint)
sess.Logger().Infof("stunreachability: measuring: %s... %s", endpoint, model.ErrorToStringOrOK(err))
events := saver.Read() events := saver.Read()
tk.NetworkEvents = append( tk.NetworkEvents = append(
tk.NetworkEvents, tracex.NewNetworkEventsList(begin, events)..., tk.NetworkEvents, tracex.NewNetworkEventsList(begin, events)...,

View File

@ -94,7 +94,9 @@ func TestRunWithInput(t *testing.T) {
measurement.Input = model.MeasurementTarget(defaultInput) measurement.Input = model.MeasurementTarget(defaultInput)
err := measurer.Run( err := measurer.Run(
context.Background(), context.Background(),
&mockable.Session{}, &mockable.Session{
MockableLogger: model.DiscardLogger,
},
measurement, measurement,
model.NewPrinterCallbacks(log.Log), model.NewPrinterCallbacks(log.Log),
) )
@ -124,7 +126,9 @@ func TestCancelledContext(t *testing.T) {
measurement.Input = model.MeasurementTarget(defaultInput) measurement.Input = model.MeasurementTarget(defaultInput)
err := measurer.Run( err := measurer.Run(
ctx, ctx,
&mockable.Session{}, &mockable.Session{
MockableLogger: model.DiscardLogger,
},
measurement, measurement,
model.NewPrinterCallbacks(log.Log), model.NewPrinterCallbacks(log.Log),
) )
@ -164,7 +168,9 @@ func TestNewClientFailure(t *testing.T) {
measurement.Input = model.MeasurementTarget(defaultInput) measurement.Input = model.MeasurementTarget(defaultInput)
err := measurer.Run( err := measurer.Run(
context.Background(), context.Background(),
&mockable.Session{}, &mockable.Session{
MockableLogger: model.DiscardLogger,
},
measurement, measurement,
model.NewPrinterCallbacks(log.Log), model.NewPrinterCallbacks(log.Log),
) )
@ -198,7 +204,9 @@ func TestStartFailure(t *testing.T) {
measurement.Input = model.MeasurementTarget(defaultInput) measurement.Input = model.MeasurementTarget(defaultInput)
err := measurer.Run( err := measurer.Run(
context.Background(), context.Background(),
&mockable.Session{}, &mockable.Session{
MockableLogger: model.DiscardLogger,
},
measurement, measurement,
model.NewPrinterCallbacks(log.Log), model.NewPrinterCallbacks(log.Log),
) )
@ -236,7 +244,9 @@ func TestReadFailure(t *testing.T) {
measurement.Input = model.MeasurementTarget(defaultInput) measurement.Input = model.MeasurementTarget(defaultInput)
err := measurer.Run( err := measurer.Run(
context.Background(), context.Background(),
&mockable.Session{}, &mockable.Session{
MockableLogger: model.DiscardLogger,
},
measurement, measurement,
model.NewPrinterCallbacks(log.Log), model.NewPrinterCallbacks(log.Log),
) )