mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
pkg/util/workqueue/delaying_queue: export contructor with custom clock
This commit is contained in:
parent
1679bed803
commit
638c02f6cd
@ -35,14 +35,17 @@ type DelayingInterface interface {
|
|||||||
|
|
||||||
// NewDelayingQueue constructs a new workqueue with delayed queuing ability
|
// NewDelayingQueue constructs a new workqueue with delayed queuing ability
|
||||||
func NewDelayingQueue() DelayingInterface {
|
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 {
|
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{
|
ret := &delayingType{
|
||||||
Interface: NewNamed(name),
|
Interface: NewNamed(name),
|
||||||
clock: clock,
|
clock: clock,
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
|
|
||||||
func TestSimpleQueue(t *testing.T) {
|
func TestSimpleQueue(t *testing.T) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := clock.NewFakeClock(time.Now())
|
||||||
q := newDelayingQueue(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
first := "foo"
|
first := "foo"
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ func TestSimpleQueue(t *testing.T) {
|
|||||||
|
|
||||||
func TestDeduping(t *testing.T) {
|
func TestDeduping(t *testing.T) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := clock.NewFakeClock(time.Now())
|
||||||
q := newDelayingQueue(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
first := "foo"
|
first := "foo"
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ func TestDeduping(t *testing.T) {
|
|||||||
|
|
||||||
func TestAddTwoFireEarly(t *testing.T) {
|
func TestAddTwoFireEarly(t *testing.T) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := clock.NewFakeClock(time.Now())
|
||||||
q := newDelayingQueue(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
first := "foo"
|
first := "foo"
|
||||||
second := "bar"
|
second := "bar"
|
||||||
@ -179,7 +179,7 @@ func TestAddTwoFireEarly(t *testing.T) {
|
|||||||
|
|
||||||
func TestCopyShifting(t *testing.T) {
|
func TestCopyShifting(t *testing.T) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := clock.NewFakeClock(time.Now())
|
||||||
q := newDelayingQueue(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
first := "foo"
|
first := "foo"
|
||||||
second := "bar"
|
second := "bar"
|
||||||
@ -217,7 +217,7 @@ func TestCopyShifting(t *testing.T) {
|
|||||||
|
|
||||||
func BenchmarkDelayingQueue_AddAfter(b *testing.B) {
|
func BenchmarkDelayingQueue_AddAfter(b *testing.B) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := clock.NewFakeClock(time.Now())
|
||||||
q := newDelayingQueue(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
// Add items
|
// Add items
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user