From 969d8b772fac01d6e21f4a3e17cbbd21727002e3 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Wed, 31 Mar 2021 14:06:05 +0200 Subject: [PATCH] fix(ooniprobe): consistent progress with maxRuntime (#277) See https://github.com/ooni/probe/issues/1299 --- cmd/ooniprobe/internal/cli/run/run.go | 1 + cmd/ooniprobe/internal/nettests/nettests.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/ooniprobe/internal/cli/run/run.go b/cmd/ooniprobe/internal/cli/run/run.go index 446e43e..e0e827d 100644 --- a/cmd/ooniprobe/internal/cli/run/run.go +++ b/cmd/ooniprobe/internal/cli/run/run.go @@ -68,6 +68,7 @@ func init() { Probe: probe, InputFiles: *inputFile, Inputs: *input, + RunType: "manual", }) }) diff --git a/cmd/ooniprobe/internal/nettests/nettests.go b/cmd/ooniprobe/internal/nettests/nettests.go index 0712691..89dd005 100644 --- a/cmd/ooniprobe/internal/nettests/nettests.go +++ b/cmd/ooniprobe/internal/nettests/nettests.go @@ -212,8 +212,18 @@ func (c *Controller) Run(builder *engine.ExperimentBuilder, inputs []string) err // OnProgress should be called when a new progress event is available. func (c *Controller) OnProgress(perc float64, msg string) { - // TODO(bassosimone): should we adjust this algorithm when we have a - // maximum runtime that we would like to honor? + // when we have maxRuntime, honor it + maxRuntime := time.Duration(c.Probe.Config().Nettests.WebsitesMaxRuntime) * time.Second + if c.RunType == "manual" && maxRuntime > 0 { + elapsed := time.Since(c.ntStartTime) + perc = float64(elapsed) / float64(maxRuntime) + eta := maxRuntime.Seconds() - elapsed.Seconds() + log.Debugf("OnProgress: %f - %s", perc, msg) + key := fmt.Sprintf("%T", c.nt) + output.Progress(key, perc, eta, msg) + return + } + // otherwise estimate the ETA log.Debugf("OnProgress: %f - %s", perc, msg) var eta float64 eta = -1.0