diff --git a/experiment/tor/tor.go b/experiment/tor/tor.go index 3fbdb3a1..28cb13cb 100644 --- a/experiment/tor/tor.go +++ b/experiment/tor/tor.go @@ -153,22 +153,30 @@ func (m *measurer) Run( measurement *model.Measurement, callbacks model.ExperimentCallbacks, ) error { - ctx, cancel := context.WithTimeout(ctx, 60*time.Second) - defer cancel() - // fetch experiment targets - clnt, err := m.newOrchestraClient(ctx, sess) + targets, err := m.gimmeTargets(ctx, sess) if err != nil { return err } - targets, err := m.fetchTorTargets(ctx, clnt) - if err != nil { - return err - } - // run the measurement + ctx, cancel := context.WithTimeout( + ctx, 15*time.Second*time.Duration(len(targets)), + ) + defer cancel() m.measureTargets(ctx, sess, measurement, callbacks, targets) return nil } +func (m *measurer) gimmeTargets( + ctx context.Context, sess model.ExperimentSession, +) (map[string]model.TorTarget, error) { + ctx, cancel := context.WithTimeout(ctx, 15*time.Second) + defer cancel() + clnt, err := m.newOrchestraClient(ctx, sess) + if err != nil { + return nil, err + } + return m.fetchTorTargets(ctx, clnt) +} + // keytarget contains a key and the related target type keytarget struct { key string diff --git a/experiment/tor/tor_test.go b/experiment/tor/tor_test.go index 1a901f28..cd950449 100644 --- a/experiment/tor/tor_test.go +++ b/experiment/tor/tor_test.go @@ -71,6 +71,32 @@ func TestUnitMeasurerMeasureFetchTorTargetsError(t *testing.T) { } } +func TestUnitMeasurerMeasureFetchTorTargetsEmptyList(t *testing.T) { + measurer := newMeasurer(Config{}) + measurer.newOrchestraClient = func(ctx context.Context, sess model.ExperimentSession) (model.ExperimentOrchestraClient, error) { + return new(orchestra.Client), nil + } + measurer.fetchTorTargets = func(ctx context.Context, clnt model.ExperimentOrchestraClient) (map[string]model.TorTarget, error) { + return nil, nil + } + measurement := new(model.Measurement) + err := measurer.Run( + context.Background(), + &mockable.ExperimentSession{ + MockableLogger: log.Log, + }, + measurement, + handler.NewPrinterCallbacks(log.Log), + ) + if err != nil { + t.Fatal(err) + } + tk := measurement.TestKeys.(*TestKeys) + if len(tk.Targets) != 0 { + t.Fatal("expected no targets here") + } +} + func TestUnitMeasurerMeasureGood(t *testing.T) { measurer := newMeasurer(Config{}) measurer.newOrchestraClient = func(ctx context.Context, sess model.ExperimentSession) (model.ExperimentOrchestraClient, error) {