Skip to content

Commit

Permalink
Fix TestCacherDontMissEventsOnReinitialization test
Browse files Browse the repository at this point in the history
Kubernetes-commit: 7682b7427171e16cc8db060ef3171cd191ff7192
  • Loading branch information
wojtek-t authored and k8s-publishing-bot committed Oct 31, 2024
1 parent 7ce6140 commit 9a71f86
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions pkg/storage/cacher/cacher_whitebox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
case 1:
podList.ListMeta = metav1.ListMeta{ResourceVersion: "10"}
default:
t.Errorf("unexpected list call: %d", listCalls)
err = fmt.Errorf("unexpected list call")
}
listCalls++
Expand All @@ -921,8 +922,11 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
for i := 12; i < 18; i++ {
w.Add(makePod(i))
}
w.Stop()
// Keep the watch open to avoid another reinitialization,
// but register it for cleanup.
t.Cleanup(func() { w.Stop() })
default:
t.Errorf("unexpected watch call: %d", watchCalls)
err = fmt.Errorf("unexpected watch call")
}
watchCalls++
Expand All @@ -944,7 +948,6 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

errCh := make(chan error, concurrency)
for i := 0; i < concurrency; i++ {
go func() {
defer wg.Done()
Expand All @@ -968,11 +971,11 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
}
rv, err := strconv.Atoi(object.(*example.Pod).ResourceVersion)
if err != nil {
errCh <- fmt.Errorf("incorrect resource version: %v", err)
t.Errorf("incorrect resource version: %v", err)
return
}
if prevRV != -1 && prevRV+1 != rv {
errCh <- fmt.Errorf("unexpected event received, prevRV=%d, rv=%d", prevRV, rv)
t.Errorf("unexpected event received, prevRV=%d, rv=%d", prevRV, rv)
return
}
prevRV = rv
Expand All @@ -981,11 +984,6 @@ func TestCacherDontMissEventsOnReinitialization(t *testing.T) {
}()
}
wg.Wait()
close(errCh)

for err := range errCh {
t.Error(err)
}
}

func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {
Expand Down

0 comments on commit 9a71f86

Please sign in to comment.