Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Cache sync cancelled should not error with timeout #1808

Merged
merged 1 commit into from Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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