MCPcopy
hub / github.com/kubernetes-sigs/controller-runtime / NonBlockingGetTest

Function NonBlockingGetTest

pkg/cache/cache_test.go:529–601  ·  view source on GitHub ↗
(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error), opts cache.Options)

Source from the content-addressed store, hash-verified

527}
528
529func NonBlockingGetTest(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error), opts cache.Options) {
530 Describe("non-blocking get test", func() {
531 var (
532 informerCache cache.Cache
533 informerCacheCancel context.CancelFunc
534 )
535 BeforeEach(func(ctx SpecContext) {
536 var informerCacheCtx context.Context
537 // Has to be derived from context.Background as it has to stay valid past the
538 // BeforeEach.
539 informerCacheCtx, informerCacheCancel = context.WithCancel(context.Background()) //nolint:forbidigo
540 Expect(cfg).NotTo(BeNil())
541
542 By("creating expected namespaces")
543 cl, err := client.New(cfg, client.Options{})
544 Expect(err).NotTo(HaveOccurred())
545 err = ensureNode(ctx, testNodeOne, cl)
546 Expect(err).NotTo(HaveOccurred())
547 err = ensureNamespace(ctx, testNamespaceOne, cl)
548 Expect(err).NotTo(HaveOccurred())
549 err = ensureNamespace(ctx, testNamespaceTwo, cl)
550 Expect(err).NotTo(HaveOccurred())
551 err = ensureNamespace(ctx, testNamespaceThree, cl)
552 Expect(err).NotTo(HaveOccurred())
553
554 By("creating the informer cache")
555 opts.NewInformer = func(_ kcache.ListerWatcher, _ runtime.Object, _ time.Duration, _ kcache.Indexers) kcache.SharedIndexInformer {
556 return controllertest.NewFakeInformer()
557 }
558 informerCache, err = createCacheFunc(cfg, opts)
559 Expect(err).NotTo(HaveOccurred())
560 By("running the cache and waiting for it to sync")
561 // pass as an arg so that we don't race between close and re-assign
562 go func(ctx context.Context) {
563 defer GinkgoRecover()
564 Expect(informerCache.Start(ctx)).To(Succeed())
565 }(informerCacheCtx)
566 Expect(informerCache.WaitForCacheSync(ctx)).To(BeTrue())
567 })
568
569 AfterEach(func() {
570 By("cleaning up created pods")
571 informerCacheCancel()
572 })
573
574 Describe("as an Informer", func() {
575 It("should be able to get informer for the object without blocking", func(specCtx SpecContext) {
576 By("getting a shared index informer for a pod")
577 pod := &corev1.Pod{
578 ObjectMeta: metav1.ObjectMeta{
579 Name: "informer-obj",
580 Namespace: "default",
581 },
582 Spec: corev1.PodSpec{
583 Containers: []corev1.Container{
584 {
585 Name: "nginx",
586 Image: "nginx",

Callers 1

cache_test.goFile · 0.85

Calls 9

NewFunction · 0.92
NewFakeInformerFunction · 0.92
BlockUntilSyncedFunction · 0.92
ensureNodeFunction · 0.85
ensureNamespaceFunction · 0.85
StartMethod · 0.65
WaitForCacheSyncMethod · 0.65
GetInformerMethod · 0.65
HasSyncedMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…