MCPcopy
hub / github.com/kubernetes/client-go / TestRunUntil

Function TestRunUntil

tools/cache/reflector_test.go:73–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestRunUntil(t *testing.T) {
74 stopCh := make(chan struct{})
75 store := NewStore(MetaNamespaceKeyFunc)
76 r := NewReflector(&testLW{}, &v1.Pod{}, store, 0)
77 fw := watch.NewFake()
78 r.listerWatcher = &testLW{
79 WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
80 return fw, nil
81 },
82 ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
83 return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "1"}}, nil
84 },
85 }
86 go r.Run(stopCh)
87 // Synchronously add a dummy pod into the watch channel so we
88 // know the RunUntil go routine is in the watch handler.
89 fw.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "bar"}})
90 close(stopCh)
91 select {
92 case _, ok := <-fw.ResultChan():
93 if ok {
94 t.Errorf("Watch channel left open after stopping the watch")
95 }
96 case <-time.After(wait.ForeverTestTimeout):
97 t.Errorf("the cancellation is at least %s late", wait.ForeverTestTimeout.String())
98 break
99 }
100}
101
102func TestReflectorResyncChan(t *testing.T) {
103 s := NewStore(MetaNamespaceKeyFunc)

Callers

nothing calls this directly

Calls 7

RunMethod · 0.95
NewStoreFunction · 0.85
NewReflectorFunction · 0.85
AddMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.65
ResultChanMethod · 0.45

Tested by

no test coverage detected