Skip to content

Commit

Permalink
Call cancel on defer
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Apr 30, 2019
1 parent 26009c3 commit ba7c1a6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions metricbeat/mb/testing/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ func RunPushMetricSetV2(timeout time.Duration, waitEvents int, metricSet mb.Push
// time and returns all of the events that occur during that period.
func RunPushMetricSetV2WithContext(timeout time.Duration, waitEvents int, metricSet mb.PushMetricSetV2WithContext) []mb.Event {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

r := &capturingPushReporterV2{eventsC: make(chan mb.Event)}

go metricSet.Run(ctx, r)
Expand All @@ -444,10 +446,8 @@ func RunPushMetricSetV2WithContext(timeout time.Duration, waitEvents int, metric
case e := <-r.eventsC:
events = append(events, e)
if len(events) >= waitEvents {
cancel()
return events
}
}
}
return events
}

0 comments on commit ba7c1a6

Please sign in to comment.