Commit ee74cc43 authored by Jan Safranek's avatar Jan Safranek

Fix fake event recorder race

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.
parent c0dfccc3
......@@ -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 {
......@@ -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
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment