mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
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.
This commit is contained in:
parent
c0dfccc388
commit
ee74cc4354
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user