Skip to content

Commit

Permalink
Fix fake event recorder race
Browse files Browse the repository at this point in the history
Event recorder should wait for some time to get all expected events, the event
may be written by another goroutine that just have finished.

It should not slow down the test in most cases, only when there is a bug and
expected event is not sent.
  • Loading branch information
jsafrane committed Jun 1, 2016
1 parent c0dfccc commit ee74cc4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/controller/persistentvolume/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,14 @@ func (r *volumeReactor) checkClaims(t *testing.T, expectedClaims []*api.Persiste
func checkEvents(t *testing.T, expectedEvents []string, ctrl *PersistentVolumeController) error {
var err error

// Read recorded events
// Read recorded events - wait up to 1 minute to get all the expected ones
// (just in case some goroutines are slower with writing)
timer := time.NewTimer(time.Minute)

fakeRecorder := ctrl.eventRecorder.(*record.FakeRecorder)
gotEvents := []string{}
finished := false
for !finished {
for len(gotEvents) < len(expectedEvents) && !finished {
select {
case event, ok := <-fakeRecorder.Events:
if ok {
Expand All @@ -372,8 +375,8 @@ func checkEvents(t *testing.T, expectedEvents []string, ctrl *PersistentVolumeCo
glog.V(5).Infof("event recorder finished")
finished = true
}
default:
glog.V(5).Infof("event recorder finished")
case _, _ = <-timer.C:
glog.V(5).Infof("event recorder timeout")
finished = true
}
}
Expand Down

0 comments on commit ee74cc4

Please sign in to comment.