Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/internal/controller/controller_test.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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