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:
parent
8931a36cb3
commit
ff1c170562
8 changed files with 203 additions and 44 deletions
|
|
@ -15,8 +15,8 @@ type FakeInputProcessorExperiment struct {
|
|||
M []*model.Measurement
|
||||
}
|
||||
|
||||
func (fipe *FakeInputProcessorExperiment) MeasureWithContext(
|
||||
ctx context.Context, input string) (*model.Measurement, error) {
|
||||
func (fipe *FakeInputProcessorExperiment) MeasureAsync(
|
||||
ctx context.Context, input string) (<-chan *model.Measurement, error) {
|
||||
if fipe.Err != nil {
|
||||
return nil, fipe.Err
|
||||
}
|
||||
|
|
@ -30,7 +30,12 @@ func (fipe *FakeInputProcessorExperiment) MeasureWithContext(
|
|||
m.AddAnnotation("foo", "baz") // would be bar below
|
||||
m.Input = model.MeasurementTarget(input)
|
||||
fipe.M = append(fipe.M, m)
|
||||
return m, nil
|
||||
out := make(chan *model.Measurement)
|
||||
go func() {
|
||||
defer close(out)
|
||||
out <- m
|
||||
}()
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func TestInputProcessorMeasurementFailed(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue