mirror of https://github.com/k3s-io/k3s
Merge pull request #78034 from liggitt/automated-cherry-pick-of-#78029-upstream-release-1.14
Automated cherry pick of #78029: Terminate watchers when watch cache is destroyedpull/564/head
commit
9150633414
|
@ -268,6 +268,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() {
|
||||
|
|
|
@ -443,3 +443,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")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue