Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tor: use targets-list-length dependent timeout #394

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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