Skip to content

Commit

Permalink
tor: use targets-list-length dependent timeout (#394)
Browse files Browse the repository at this point in the history
Closes #288

While there, I figured it made sense to add one extra test to make sure
we can gracefully handle the case where the orchestra API gives us no
targets.
  • Loading branch information
bassosimone authored Mar 9, 2020
1 parent 30ee2a6 commit e5272b1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
26 changes: 17 additions & 9 deletions experiment/tor/tor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions experiment/tor/tor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e5272b1

Please sign in to comment.