Skip to content
Permalink
Browse files

Merge pull request #78036 from liggitt/automated-cherry-pick-of-#7802…

…9-upstream-release-1.12

Automated cherry pick of #78029: Terminate watchers when watch cache is destroyed
  • Loading branch information...
k8s-ci-robot committed May 23, 2019
2 parents 9053aa7 + f1c00f3 commit e09f5c40b55c91f681a46ee17f9bc447eeacee57
@@ -234,6 +234,7 @@ func NewCacherFromConfig(config Config) *Cacher {
cacher.stopWg.Add(1)
go func() {
defer cacher.stopWg.Done()
defer cacher.terminateAllWatchers()
wait.Until(
func() {
if !cacher.isStopped() {
@@ -438,3 +438,39 @@ func TestWatcherNotGoingBackInTime(t *testing.T) {
}
}
}

func TestCacheWatcherStoppedOnDestroy(t *testing.T) {
backingStorage := &dummyStorage{}
cacher, _ := newTestCacher(backingStorage, 1000)
defer cacher.Stop()

// Wait until cacher is initialized.
cacher.ready.wait()

w, err := cacher.Watch(context.Background(), "pods/ns", "0", storage.Everything)
if err != nil {
t.Fatalf("Failed to create watch: %v", err)
}

watchClosed := make(chan struct{})
go func() {
defer close(watchClosed)
for event := range w.ResultChan() {
switch event.Type {
case watch.Added, watch.Modified, watch.Deleted:
// ok
default:
t.Errorf("unexpected event %#v", event)
}
}
}()

cacher.Stop()

select {
case <-watchClosed:
case <-time.After(wait.ForeverTestTimeout):
t.Errorf("timed out waiting for watch to close")
}

}

0 comments on commit e09f5c4

Please sign in to comment.
You can’t perform that action at this time.