Skip to content

Commit

Permalink
Merge pull request #1808 from erikgb/fix/issue-1786
Browse files Browse the repository at this point in the history
🐛 Cache sync cancelled should not error with timeout
  • Loading branch information
k8s-ci-robot committed Feb 16, 2022
2 parents 5b2eaae + 5ed64c9 commit 3fb2cfd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/internal/controller/controller_test.go
Expand Up @@ -154,6 +154,32 @@ var _ = Describe("controller", func() {
Expect(err.Error()).To(ContainSubstring("failed to wait for testcontroller caches to sync: timed out waiting for cache to be synced"))
})

It("should not error when context cancelled", func() {
ctrl.CacheSyncTimeout = 1 * time.Second

sourceSynced := make(chan struct{})
c, err := cache.New(cfg, cache.Options{})
Expect(err).NotTo(HaveOccurred())
c = &cacheWithIndefinitelyBlockingGetInformer{c}
ctrl.startWatches = []watchDescription{{
src: &singnallingSourceWrapper{
SyncingSource: source.NewKindWithCache(&appsv1.Deployment{}, c),
cacheSyncDone: sourceSynced,
},
}}
ctrl.Name = "testcontroller"

ctx, cancel := context.WithCancel(context.TODO())
go func() {
defer GinkgoRecover()
err = ctrl.Start(ctx)
Expect(err).To(Succeed())
}()

cancel()
<-sourceSynced
})

It("should not error when cache sync timeout is of sufficiently high", func() {
ctrl.CacheSyncTimeout = 1 * time.Second

Expand Down
3 changes: 3 additions & 0 deletions pkg/source/source.go
Expand Up @@ -175,6 +175,9 @@ func (ks *Kind) WaitForSync(ctx context.Context) error {
return err
case <-ctx.Done():
ks.startCancel()
if ctx.Err() == context.Canceled {
return nil
}
return errors.New("timed out waiting for cache to be synced")
}
}
Expand Down

0 comments on commit 3fb2cfd

Please sign in to comment.