| 186 | } |
| 187 | |
| 188 | func TestUntilWithSync(t *testing.T) { |
| 189 | // FIXME: test preconditions |
| 190 | tt := []struct { |
| 191 | name string |
| 192 | lw *cache.ListWatch |
| 193 | preconditionFunc PreconditionFunc |
| 194 | conditionFunc ConditionFunc |
| 195 | expectedErr error |
| 196 | expectedEvent *watch.Event |
| 197 | }{ |
| 198 | { |
| 199 | name: "doesn't wait for sync with no precondition", |
| 200 | lw: &cache.ListWatch{ |
| 201 | ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { |
| 202 | select {} |
| 203 | }, |
| 204 | WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { |
| 205 | select {} |
| 206 | }, |
| 207 | }, |
| 208 | preconditionFunc: nil, |
| 209 | conditionFunc: func(e watch.Event) (bool, error) { |
| 210 | return true, nil |
| 211 | }, |
| 212 | expectedErr: errors.New("timed out waiting for the condition"), |
| 213 | expectedEvent: nil, |
| 214 | }, |
| 215 | { |
| 216 | name: "waits indefinitely with precondition if it can't sync", |
| 217 | lw: &cache.ListWatch{ |
| 218 | ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { |
| 219 | select {} |
| 220 | }, |
| 221 | WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { |
| 222 | select {} |
| 223 | }, |
| 224 | }, |
| 225 | preconditionFunc: func(store cache.Store) (bool, error) { |
| 226 | return true, nil |
| 227 | }, |
| 228 | conditionFunc: func(e watch.Event) (bool, error) { |
| 229 | return true, nil |
| 230 | }, |
| 231 | expectedErr: errors.New("UntilWithSync: unable to sync caches: context deadline exceeded"), |
| 232 | expectedEvent: nil, |
| 233 | }, |
| 234 | { |
| 235 | name: "precondition can stop the loop", |
| 236 | lw: func() *cache.ListWatch { |
| 237 | fakeclient := fakeclient.NewSimpleClientset(&corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "first"}}) |
| 238 | |
| 239 | return &cache.ListWatch{ |
| 240 | ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { |
| 241 | return fakeclient.CoreV1().Secrets("").List(options) |
| 242 | }, |
| 243 | WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { |
| 244 | return fakeclient.CoreV1().Secrets("").Watch(options) |
| 245 | }, |