pkg/util/workqueue/delaying_queue: export contructor with custom clock

This commit is contained in:
Jacek Kaniuk 2019-10-23 16:07:38 +02:00
parent 1679bed803
commit 638c02f6cd
2 changed files with 11 additions and 8 deletions

View File

@ -35,14 +35,17 @@ type DelayingInterface interface {
// NewDelayingQueue constructs a new workqueue with delayed queuing ability
func NewDelayingQueue() DelayingInterface {
return newDelayingQueue(clock.RealClock{}, "")
return NewDelayingQueueWithCustomClock(clock.RealClock{}, "")
}
// NewNamedDelayingQueue constructs a new named workqueue with delayed queuing ability
func NewNamedDelayingQueue(name string) DelayingInterface {
return newDelayingQueue(clock.RealClock{}, name)
return NewDelayingQueueWithCustomClock(clock.RealClock{}, name)
}
func newDelayingQueue(clock clock.Clock, name string) DelayingInterface {
// NewDelayingQueueWithCustomClock constructs a new named workqueue
// with ability to inject real or fake clock for testing purposes
func NewDelayingQueueWithCustomClock(clock clock.Clock, name string) DelayingInterface {
ret := &delayingType{
Interface: NewNamed(name),
clock: clock,

View File

@ -29,7 +29,7 @@ import (
func TestSimpleQueue(t *testing.T) {
fakeClock := clock.NewFakeClock(time.Now())
q := newDelayingQueue(fakeClock, "")
q := NewDelayingQueueWithCustomClock(fakeClock, "")
first := "foo"
@ -71,7 +71,7 @@ func TestSimpleQueue(t *testing.T) {
func TestDeduping(t *testing.T) {
fakeClock := clock.NewFakeClock(time.Now())
q := newDelayingQueue(fakeClock, "")
q := NewDelayingQueueWithCustomClock(fakeClock, "")
first := "foo"
@ -130,7 +130,7 @@ func TestDeduping(t *testing.T) {
func TestAddTwoFireEarly(t *testing.T) {
fakeClock := clock.NewFakeClock(time.Now())
q := newDelayingQueue(fakeClock, "")
q := NewDelayingQueueWithCustomClock(fakeClock, "")
first := "foo"
second := "bar"
@ -179,7 +179,7 @@ func TestAddTwoFireEarly(t *testing.T) {
func TestCopyShifting(t *testing.T) {
fakeClock := clock.NewFakeClock(time.Now())
q := newDelayingQueue(fakeClock, "")
q := NewDelayingQueueWithCustomClock(fakeClock, "")
first := "foo"
second := "bar"
@ -217,7 +217,7 @@ func TestCopyShifting(t *testing.T) {
func BenchmarkDelayingQueue_AddAfter(b *testing.B) {
fakeClock := clock.NewFakeClock(time.Now())
q := newDelayingQueue(fakeClock, "")
q := NewDelayingQueueWithCustomClock(fakeClock, "")
// Add items
for n := 0; n < b.N; n++ {