(t *testing.T)
| 2725 | } |
| 2726 | |
| 2727 | func TestIndexFieldDoesNotBlock(t *testing.T) { |
| 2728 | t.Parallel() |
| 2729 | synctest.Test(t, func(t *testing.T) { |
| 2730 | g := NewWithT(t) |
| 2731 | |
| 2732 | fakeInformer := controllertest.NewFakeInformer() |
| 2733 | c, err := cache.New(&rest.Config{}, cache.Options{ |
| 2734 | Mapper: &fakeRESTMapper{}, |
| 2735 | NewInformer: func(kcache.ListerWatcher, runtime.Object, time.Duration, kcache.Indexers) kcache.SharedIndexInformer { |
| 2736 | return fakeInformer |
| 2737 | }, |
| 2738 | }) |
| 2739 | g.Expect(err).NotTo(HaveOccurred()) |
| 2740 | |
| 2741 | ctx, cancel := context.WithCancel(t.Context()) |
| 2742 | defer cancel() |
| 2743 | cacheDone := make(chan struct{}) |
| 2744 | go func() { |
| 2745 | g.Expect(c.Start(ctx)).To(Succeed()) |
| 2746 | close(cacheDone) |
| 2747 | }() |
| 2748 | synctest.Wait() // Let the cache finish starting |
| 2749 | |
| 2750 | // Call IndexField before informer is synced with a short timeout |
| 2751 | // If IndexField blocks waiting for sync, this will timeout |
| 2752 | indexCtx, indexCancel := context.WithTimeout(ctx, 100*time.Millisecond) |
| 2753 | defer indexCancel() |
| 2754 | fieldName := "testField" |
| 2755 | indexFunc := func(obj client.Object) []string { |
| 2756 | return []string{"test-value"} |
| 2757 | } |
| 2758 | pod := &corev1.Pod{} |
| 2759 | err = c.IndexField(indexCtx, pod, fieldName, indexFunc) |
| 2760 | g.Expect(err).NotTo(HaveOccurred()) |
| 2761 | |
| 2762 | cancel() |
| 2763 | <-cacheDone |
| 2764 | }) |
| 2765 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…