Skip to content

Commit 9a71f86

Browse files
wojtek-tk8s-publishing-bot
authored andcommitted
Fix TestCacherDontMissEventsOnReinitialization test
Kubernetes-commit: 7682b7427171e16cc8db060ef3171cd191ff7192
1 parent 7ce6140 commit 9a71f86

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

pkg/storage/cacher/cacher_whitebox_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
899899
case 1:
900900
podList.ListMeta = metav1.ListMeta{ResourceVersion: "10"}
901901
default:
902+
t.Errorf("unexpected list call: %d", listCalls)
902903
err = fmt.Errorf("unexpected list call")
903904
}
904905
listCalls++
@@ -921,8 +922,11 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
921922
for i := 12; i < 18; i++ {
922923
w.Add(makePod(i))
923924
}
924-
w.Stop()
925+
// Keep the watch open to avoid another reinitialization,
926+
// but register it for cleanup.
927+
t.Cleanup(func() { w.Stop() })
925928
default:
929+
t.Errorf("unexpected watch call: %d", watchCalls)
926930
err = fmt.Errorf("unexpected watch call")
927931
}
928932
watchCalls++
@@ -944,7 +948,6 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
944948
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
945949
defer cancel()
946950

947-
errCh := make(chan error, concurrency)
948951
for i := 0; i < concurrency; i++ {
949952
go func() {
950953
defer wg.Done()
@@ -968,11 +971,11 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
968971
}
969972
rv, err := strconv.Atoi(object.(*example.Pod).ResourceVersion)
970973
if err != nil {
971-
errCh <- fmt.Errorf("incorrect resource version: %v", err)
974+
t.Errorf("incorrect resource version: %v", err)
972975
return
973976
}
974977
if prevRV != -1 && prevRV+1 != rv {
975-
errCh <- fmt.Errorf("unexpected event received, prevRV=%d, rv=%d", prevRV, rv)
978+
t.Errorf("unexpected event received, prevRV=%d, rv=%d", prevRV, rv)
976979
return
977980
}
978981
prevRV = rv
@@ -981,11 +984,6 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
981984
}()
982985
}
983986
wg.Wait()
984-
close(errCh)
985-
986-
for err := range errCh {
987-
t.Error(err)
988-
}
989987
}
990988

991989
func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {

0 commit comments

Comments
 (0)