Skip to content

Commit d35ea21

Browse files
committed
Fix TestCacherDontMissEventsOnReinitialization test
1 parent 453efd7 commit d35ea21

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
905905
case 1:
906906
podList.ListMeta = metav1.ListMeta{ResourceVersion: "10"}
907907
default:
908+
t.Errorf("unexpected list call: %d", listCalls)
908909
err = fmt.Errorf("unexpected list call")
909910
}
910911
listCalls++
@@ -927,8 +928,11 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
927928
for i := 12; i < 18; i++ {
928929
w.Add(makePod(i))
929930
}
930-
w.Stop()
931+
// Keep the watch open to avoid another reinitialization,
932+
// but register it for cleanup.
933+
t.Cleanup(func() { w.Stop() })
931934
default:
935+
t.Errorf("unexpected watch call: %d", watchCalls)
932936
err = fmt.Errorf("unexpected watch call")
933937
}
934938
watchCalls++
@@ -950,7 +954,6 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
950954
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
951955
defer cancel()
952956

953-
errCh := make(chan error, concurrency)
954957
for i := 0; i < concurrency; i++ {
955958
go func() {
956959
defer wg.Done()
@@ -974,11 +977,11 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
974977
}
975978
rv, err := strconv.Atoi(object.(*example.Pod).ResourceVersion)
976979
if err != nil {
977-
errCh <- fmt.Errorf("incorrect resource version: %v", err)
980+
t.Errorf("incorrect resource version: %v", err)
978981
return
979982
}
980983
if prevRV != -1 && prevRV+1 != rv {
981-
errCh <- fmt.Errorf("unexpected event received, prevRV=%d, rv=%d", prevRV, rv)
984+
t.Errorf("unexpected event received, prevRV=%d, rv=%d", prevRV, rv)
982985
return
983986
}
984987
prevRV = rv
@@ -987,11 +990,6 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
987990
}()
988991
}
989992
wg.Wait()
990-
close(errCh)
991-
992-
for err := range errCh {
993-
t.Error(err)
994-
}
995993
}
996994

997995
func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {

0 commit comments

Comments
 (0)