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

Function TestRateLimitingQueue

util/workqueue/rate_limiting_queue_test.go:26–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestRateLimitingQueue(t *testing.T) {
27 limiter := NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Second)
28 queue := NewRateLimitingQueue(limiter).(*rateLimitingType)
29 fakeClock := clock.NewFakeClock(time.Now())
30 delayingQueue := &delayingType{
31 Interface: New(),
32 clock: fakeClock,
33 heartbeat: fakeClock.NewTicker(maxWait),
34 stopCh: make(chan struct{}),
35 waitingForAddCh: make(chan *waitFor, 1000),
36 metrics: newRetryMetrics(""),
37 deprecatedMetrics: newDeprecatedRetryMetrics(""),
38 }
39 queue.DelayingInterface = delayingQueue
40
41 queue.AddRateLimited("one")
42 waitEntry := <-delayingQueue.waitingForAddCh
43 if e, a := 1*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
44 t.Errorf("expected %v, got %v", e, a)
45 }
46 queue.AddRateLimited("one")
47 waitEntry = <-delayingQueue.waitingForAddCh
48 if e, a := 2*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
49 t.Errorf("expected %v, got %v", e, a)
50 }
51 if e, a := 2, queue.NumRequeues("one"); e != a {
52 t.Errorf("expected %v, got %v", e, a)
53 }
54
55 queue.AddRateLimited("two")
56 waitEntry = <-delayingQueue.waitingForAddCh
57 if e, a := 1*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
58 t.Errorf("expected %v, got %v", e, a)
59 }
60 queue.AddRateLimited("two")
61 waitEntry = <-delayingQueue.waitingForAddCh
62 if e, a := 2*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
63 t.Errorf("expected %v, got %v", e, a)
64 }
65
66 queue.Forget("one")
67 if e, a := 0, queue.NumRequeues("one"); e != a {
68 t.Errorf("expected %v, got %v", e, a)
69 }
70 queue.AddRateLimited("one")
71 waitEntry = <-delayingQueue.waitingForAddCh
72 if e, a := 1*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
73 t.Errorf("expected %v, got %v", e, a)
74 }
75
76}

Callers

nothing calls this directly

Calls 10

NewRateLimitingQueueFunction · 0.85
newRetryMetricsFunction · 0.85
NewFunction · 0.70
NowMethod · 0.65
AddRateLimitedMethod · 0.65
ErrorfMethod · 0.65
NumRequeuesMethod · 0.65
ForgetMethod · 0.65

Tested by

no test coverage detected