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

Function TestResyncCheckPeriod

tools/cache/shared_informer_test.go:185–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

183}
184
185func TestResyncCheckPeriod(t *testing.T) {
186 // source simulates an apiserver object endpoint.
187 source := fcache.NewFakeControllerSource()
188
189 // create the shared informer and resync every 12 hours
190 informer := NewSharedInformer(source, &v1.Pod{}, 12*time.Hour).(*sharedIndexInformer)
191
192 clock := clock.NewFakeClock(time.Now())
193 informer.clock = clock
194 informer.processor.clock = clock
195
196 // listener 1, never resync
197 listener1 := newTestListener("listener1", 0)
198 informer.AddEventHandlerWithResyncPeriod(listener1, listener1.resyncPeriod)
199 if e, a := 12*time.Hour, informer.resyncCheckPeriod; e != a {
200 t.Errorf("expected %d, got %d", e, a)
201 }
202 if e, a := time.Duration(0), informer.processor.listeners[0].resyncPeriod; e != a {
203 t.Errorf("expected %d, got %d", e, a)
204 }
205
206 // listener 2, resync every minute
207 listener2 := newTestListener("listener2", 1*time.Minute)
208 informer.AddEventHandlerWithResyncPeriod(listener2, listener2.resyncPeriod)
209 if e, a := 1*time.Minute, informer.resyncCheckPeriod; e != a {
210 t.Errorf("expected %d, got %d", e, a)
211 }
212 if e, a := time.Duration(0), informer.processor.listeners[0].resyncPeriod; e != a {
213 t.Errorf("expected %d, got %d", e, a)
214 }
215 if e, a := 1*time.Minute, informer.processor.listeners[1].resyncPeriod; e != a {
216 t.Errorf("expected %d, got %d", e, a)
217 }
218
219 // listener 3, resync every 55 seconds
220 listener3 := newTestListener("listener3", 55*time.Second)
221 informer.AddEventHandlerWithResyncPeriod(listener3, listener3.resyncPeriod)
222 if e, a := 55*time.Second, informer.resyncCheckPeriod; e != a {
223 t.Errorf("expected %d, got %d", e, a)
224 }
225 if e, a := time.Duration(0), informer.processor.listeners[0].resyncPeriod; e != a {
226 t.Errorf("expected %d, got %d", e, a)
227 }
228 if e, a := 1*time.Minute, informer.processor.listeners[1].resyncPeriod; e != a {
229 t.Errorf("expected %d, got %d", e, a)
230 }
231 if e, a := 55*time.Second, informer.processor.listeners[2].resyncPeriod; e != a {
232 t.Errorf("expected %d, got %d", e, a)
233 }
234
235 // listener 4, resync every 5 seconds
236 listener4 := newTestListener("listener4", 5*time.Second)
237 informer.AddEventHandlerWithResyncPeriod(listener4, listener4.resyncPeriod)
238 if e, a := 5*time.Second, informer.resyncCheckPeriod; e != a {
239 t.Errorf("expected %d, got %d", e, a)
240 }
241 if e, a := time.Duration(0), informer.processor.listeners[0].resyncPeriod; e != a {
242 t.Errorf("expected %d, got %d", e, a)

Callers

nothing calls this directly

Calls 5

NewSharedInformerFunction · 0.85
newTestListenerFunction · 0.85
NowMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected