(t *testing.T)
| 2668 | } |
| 2669 | |
| 2670 | func TestReaderWaitsForCacheSync(t *testing.T) { |
| 2671 | t.Parallel() |
| 2672 | for _, readerFailOnMissingInformer := range []bool{true, false} { |
| 2673 | t.Run(fmt.Sprintf("ReaderFailOnMissingInformer=%v", readerFailOnMissingInformer), func(t *testing.T) { |
| 2674 | t.Parallel() |
| 2675 | synctest.Test(t, func(t *testing.T) { |
| 2676 | g := NewWithT(t) |
| 2677 | |
| 2678 | fakeInformer := controllertest.NewFakeInformer() |
| 2679 | c, err := cache.New(&rest.Config{}, cache.Options{ |
| 2680 | ReaderFailOnMissingInformer: readerFailOnMissingInformer, |
| 2681 | Mapper: &fakeRESTMapper{}, |
| 2682 | NewInformer: func(kcache.ListerWatcher, runtime.Object, time.Duration, kcache.Indexers) kcache.SharedIndexInformer { |
| 2683 | return fakeInformer |
| 2684 | }, |
| 2685 | }) |
| 2686 | g.Expect(err).NotTo(HaveOccurred()) |
| 2687 | |
| 2688 | ctx, cancel := context.WithCancel(t.Context()) |
| 2689 | defer cancel() |
| 2690 | cacheDone := make(chan struct{}) |
| 2691 | go func() { |
| 2692 | g.Expect(c.Start(ctx)).To(Succeed()) |
| 2693 | close(cacheDone) |
| 2694 | }() |
| 2695 | synctest.Wait() // Let the cache finish starting |
| 2696 | _, err = c.GetInformer(ctx, &corev1.Service{}, cache.BlockUntilSynced(false)) |
| 2697 | g.Expect(err).ToNot(HaveOccurred()) |
| 2698 | |
| 2699 | listCtx, listCtxCancel := context.WithTimeout(ctx, time.Second) |
| 2700 | defer listCtxCancel() |
| 2701 | services := &corev1.ServiceList{} |
| 2702 | err = c.List(listCtx, services) |
| 2703 | g.Expect(err).To(HaveOccurred()) |
| 2704 | g.Expect(apierrors.IsTimeout(err)).To(BeTrue()) |
| 2705 | |
| 2706 | getCtx, getCtxCancel := context.WithTimeout(ctx, time.Second) |
| 2707 | defer getCtxCancel() |
| 2708 | err = c.Get(getCtx, client.ObjectKey{Name: "default", Namespace: "kubernetes"}, &corev1.Service{}) |
| 2709 | g.Expect(err).To(HaveOccurred()) |
| 2710 | g.Expect(apierrors.IsTimeout(err)).To(BeTrue()) |
| 2711 | |
| 2712 | fakeInformer.Synced() |
| 2713 | |
| 2714 | g.Expect(c.List(ctx, services)).To(Succeed()) |
| 2715 | |
| 2716 | err = c.Get(getCtx, client.ObjectKey{Name: "default", Namespace: "kubernetes"}, &corev1.Service{}) |
| 2717 | g.Expect(err).To(HaveOccurred()) |
| 2718 | g.Expect(apierrors.IsNotFound(err)).To(BeTrue()) |
| 2719 | |
| 2720 | cancel() |
| 2721 | <-cacheDone |
| 2722 | }) |
| 2723 | }) |
| 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | func TestIndexFieldDoesNotBlock(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…