(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func 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 | } |
nothing calls this directly
no test coverage detected