@@ -124,15 +124,12 @@ var _ = Describe("controller", func() {
124
124
125
125
It ("should error when cache sync timeout occurs" , func (done Done ) {
126
126
ctrl .CacheSyncTimeout = 10 * time .Nanosecond
127
+
127
128
c , err := cache .New (cfg , cache.Options {})
128
129
Expect (err ).NotTo (HaveOccurred ())
129
- _ , err = c .GetInformer (context .TODO (), & appsv1.Deployment {})
130
- Expect (err ).NotTo (HaveOccurred ())
131
- sync := false
130
+
132
131
ctrl .startWatches = []watchDescription {{
133
- src : source .NewKindWithCache (& appsv1.Deployment {}, & informertest.FakeInformers {
134
- Synced : & sync ,
135
- }),
132
+ src : source .NewKindWithCache (& appsv1.Deployment {}, c ),
136
133
}}
137
134
138
135
err = ctrl .Start (context .TODO ())
@@ -142,39 +139,35 @@ var _ = Describe("controller", func() {
142
139
close (done )
143
140
})
144
141
145
- It ("should not error when cache sync time out is of reasonable value " , func (done Done ) {
142
+ It ("should not error when cache sync timeout is of sufficiently high " , func (done Done ) {
146
143
ctrl .CacheSyncTimeout = 1 * time .Second
144
+
145
+ ctx , cancel := context .WithCancel (context .Background ())
146
+ defer cancel ()
147
+
148
+ sourceSynced := make (chan struct {})
147
149
c , err := cache .New (cfg , cache.Options {})
148
150
Expect (err ).NotTo (HaveOccurred ())
149
151
ctrl .startWatches = []watchDescription {{
150
- src : source .NewKindWithCache (& appsv1.Deployment {}, c ),
152
+ src : & singnallingSourceWrapper {
153
+ SyncingSource : source .NewKindWithCache (& appsv1.Deployment {}, c ),
154
+ cacheSyncDone : sourceSynced ,
155
+ },
151
156
}}
152
157
153
- By ("running the cache and waiting for it to sync" )
154
158
go func () {
155
159
defer GinkgoRecover ()
156
- Expect (c .Start (context . TODO () )).To (Succeed ())
160
+ Expect (c .Start (ctx )).To (Succeed ())
157
161
}()
158
- close (done )
159
- })
160
162
161
- It ("should error when timeout is set to a very low value such that cache cannot sync" , func (done Done ) {
162
- ctrl .CacheSyncTimeout = 1 * time .Nanosecond
163
- c , err := cache .New (cfg , cache.Options {})
164
- Expect (err ).NotTo (HaveOccurred ())
165
- ctrl .startWatches = []watchDescription {{
166
- src : source .NewKindWithCache (& appsv1.Deployment {}, c ),
167
- }}
168
-
169
- By ("running the cache and waiting for it to sync" )
170
163
go func () {
171
164
defer GinkgoRecover ()
172
- err = ctrl .Start (context .TODO ())
173
- Expect (err ).To (HaveOccurred ())
174
- Expect (err .Error ()).To (ContainSubstring ("cache did not sync" ))
165
+ Expect (ctrl .Start (ctx )).To (Succeed ())
175
166
}()
167
+
168
+ <- sourceSynced
176
169
close (done )
177
- })
170
+ }, 10.0 )
178
171
179
172
It ("should call Start on sources with the appropriate EventHandler, Queue, and Predicates" , func () {
180
173
pr1 := & predicate.Funcs {}
@@ -865,3 +858,15 @@ func (f *fakeReconciler) Reconcile(_ context.Context, r reconcile.Request) (reco
865
858
}
866
859
return res .Result , res .Err
867
860
}
861
+
862
+ type singnallingSourceWrapper struct {
863
+ cacheSyncDone chan struct {}
864
+ source.SyncingSource
865
+ }
866
+
867
+ func (s * singnallingSourceWrapper ) WaitForSync (ctx context.Context ) error {
868
+ defer func () {
869
+ close (s .cacheSyncDone )
870
+ }()
871
+ return s .SyncingSource .WaitForSync (ctx )
872
+ }
0 commit comments