feat(engine): allow runner to return many measurements (#527)
This is required to implement websteps, which is currently tracked by https://github.com/ooni/probe/issues/1733. We introduce the concept of async runner. An async runner will post measurements on a channel until it is done. When it is done, it will close the channel to notify the reader about that. This change causes sync experiments now to strictly return either a non-nil measurement or a non-nil error. While this is a pretty much obvious situation in golang, we had some parts of the codebase that were not robust to this assumption and attempted to submit a measurement after the measure call returned an error. Luckily, we had enough tests to catch this change in our assumption and this is why there are extra docs and tests changes.
This commit is contained in:
@@ -460,15 +460,12 @@ type experimentWrapper struct {
|
||||
total int
|
||||
}
|
||||
|
||||
func (ew *experimentWrapper) MeasureWithContext(
|
||||
ctx context.Context, idx int, input string) (*model.Measurement, error) {
|
||||
func (ew *experimentWrapper) MeasureAsync(
|
||||
ctx context.Context, input string, idx int) (<-chan *model.Measurement, error) {
|
||||
if input != "" {
|
||||
log.Infof("[%d/%d] running with input: %s", idx+1, ew.total, input)
|
||||
}
|
||||
measurement, err := ew.child.MeasureWithContext(ctx, idx, input)
|
||||
warnOnError(err, "measurement failed")
|
||||
// policy: we do not stop the loop if the measurement fails
|
||||
return measurement, nil
|
||||
return ew.child.MeasureAsync(ctx, input, idx)
|
||||
}
|
||||
|
||||
type submitterWrapper struct {
|
||||
|
||||
Reference in New Issue
Block a user