File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,32 @@ var _ = Describe("controller", func() {
154
154
Expect (err .Error ()).To (ContainSubstring ("failed to wait for testcontroller caches to sync: timed out waiting for cache to be synced" ))
155
155
})
156
156
157
+ It ("should not error when context cancelled" , func () {
158
+ ctrl .CacheSyncTimeout = 1 * time .Second
159
+
160
+ sourceSynced := make (chan struct {})
161
+ c , err := cache .New (cfg , cache.Options {})
162
+ Expect (err ).NotTo (HaveOccurred ())
163
+ c = & cacheWithIndefinitelyBlockingGetInformer {c }
164
+ ctrl .startWatches = []watchDescription {{
165
+ src : & singnallingSourceWrapper {
166
+ SyncingSource : source .NewKindWithCache (& appsv1.Deployment {}, c ),
167
+ cacheSyncDone : sourceSynced ,
168
+ },
169
+ }}
170
+ ctrl .Name = "testcontroller"
171
+
172
+ ctx , cancel := context .WithCancel (context .TODO ())
173
+ go func () {
174
+ defer GinkgoRecover ()
175
+ err = ctrl .Start (ctx )
176
+ Expect (err ).To (Succeed ())
177
+ }()
178
+
179
+ cancel ()
180
+ <- sourceSynced
181
+ })
182
+
157
183
It ("should not error when cache sync timeout is of sufficiently high" , func () {
158
184
ctrl .CacheSyncTimeout = 1 * time .Second
159
185
Original file line number Diff line number Diff line change @@ -175,6 +175,9 @@ func (ks *Kind) WaitForSync(ctx context.Context) error {
175
175
return err
176
176
case <- ctx .Done ():
177
177
ks .startCancel ()
178
+ if ctx .Err () == context .Canceled {
179
+ return nil
180
+ }
178
181
return errors .New ("timed out waiting for cache to be synced" )
179
182
}
180
183
}
You can’t perform that action at this time.
0 commit comments