mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Migratet to k8s.io/utils/clock in workqueue
This commit is contained in:
parent
ef9a90fac1
commit
392292ba81
@ -21,8 +21,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
|
"k8s.io/utils/clock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DelayingInterface is an Interface that can Add an item at a later time. This makes it easier to
|
// DelayingInterface is an Interface that can Add an item at a later time. This makes it easier to
|
||||||
@ -51,11 +51,11 @@ func NewNamedDelayingQueue(name string) DelayingInterface {
|
|||||||
|
|
||||||
// NewDelayingQueueWithCustomClock constructs a new named workqueue
|
// NewDelayingQueueWithCustomClock constructs a new named workqueue
|
||||||
// with ability to inject real or fake clock for testing purposes
|
// with ability to inject real or fake clock for testing purposes
|
||||||
func NewDelayingQueueWithCustomClock(clock clock.Clock, name string) DelayingInterface {
|
func NewDelayingQueueWithCustomClock(clock clock.WithTicker, name string) DelayingInterface {
|
||||||
return newDelayingQueue(clock, NewNamed(name), name)
|
return newDelayingQueue(clock, NewNamed(name), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDelayingQueue(clock clock.Clock, q Interface, name string) *delayingType {
|
func newDelayingQueue(clock clock.WithTicker, q Interface, name string) *delayingType {
|
||||||
ret := &delayingType{
|
ret := &delayingType{
|
||||||
Interface: q,
|
Interface: q,
|
||||||
clock: clock,
|
clock: clock,
|
||||||
|
@ -23,12 +23,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSimpleQueue(t *testing.T) {
|
func TestSimpleQueue(t *testing.T) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := testingclock.NewFakeClock(time.Now())
|
||||||
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
first := "foo"
|
first := "foo"
|
||||||
@ -70,7 +70,7 @@ func TestSimpleQueue(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeduping(t *testing.T) {
|
func TestDeduping(t *testing.T) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := testingclock.NewFakeClock(time.Now())
|
||||||
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
first := "foo"
|
first := "foo"
|
||||||
@ -129,7 +129,7 @@ func TestDeduping(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddTwoFireEarly(t *testing.T) {
|
func TestAddTwoFireEarly(t *testing.T) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := testingclock.NewFakeClock(time.Now())
|
||||||
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
first := "foo"
|
first := "foo"
|
||||||
@ -178,7 +178,7 @@ func TestAddTwoFireEarly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCopyShifting(t *testing.T) {
|
func TestCopyShifting(t *testing.T) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := testingclock.NewFakeClock(time.Now())
|
||||||
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
first := "foo"
|
first := "foo"
|
||||||
@ -216,7 +216,7 @@ func TestCopyShifting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkDelayingQueue_AddAfter(b *testing.B) {
|
func BenchmarkDelayingQueue_AddAfter(b *testing.B) {
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := testingclock.NewFakeClock(time.Now())
|
||||||
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
q := NewDelayingQueueWithCustomClock(fakeClock, "")
|
||||||
|
|
||||||
// Add items
|
// Add items
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
"k8s.io/utils/clock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This file provides abstractions for setting the provider (e.g., prometheus)
|
// This file provides abstractions for setting the provider (e.g., prometheus)
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testMetrics struct {
|
type testMetrics struct {
|
||||||
@ -40,7 +40,7 @@ func TestMetricShutdown(t *testing.T) {
|
|||||||
m := &testMetrics{
|
m := &testMetrics{
|
||||||
updateCalled: ch,
|
updateCalled: ch,
|
||||||
}
|
}
|
||||||
c := clock.NewFakeClock(time.Now())
|
c := testingclock.NewFakeClock(time.Now())
|
||||||
q := newQueue(c, m, time.Millisecond)
|
q := newQueue(c, m, time.Millisecond)
|
||||||
for !c.HasWaiters() {
|
for !c.HasWaiters() {
|
||||||
// Wait for the go routine to call NewTicker()
|
// Wait for the go routine to call NewTicker()
|
||||||
@ -170,7 +170,7 @@ func (m *testMetricsProvider) NewRetriesMetric(name string) CounterMetric {
|
|||||||
func TestMetrics(t *testing.T) {
|
func TestMetrics(t *testing.T) {
|
||||||
mp := testMetricsProvider{}
|
mp := testMetricsProvider{}
|
||||||
t0 := time.Unix(0, 0)
|
t0 := time.Unix(0, 0)
|
||||||
c := clock.NewFakeClock(t0)
|
c := testingclock.NewFakeClock(t0)
|
||||||
mf := queueMetricsFactory{metricsProvider: &mp}
|
mf := queueMetricsFactory{metricsProvider: &mp}
|
||||||
m := mf.newQueueMetrics("test", c)
|
m := mf.newQueueMetrics("test", c)
|
||||||
q := newQueue(c, m, time.Millisecond)
|
q := newQueue(c, m, time.Millisecond)
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
"k8s.io/utils/clock"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
@ -46,7 +46,7 @@ func NewNamed(name string) *Type {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newQueue(c clock.Clock, metrics queueMetrics, updatePeriod time.Duration) *Type {
|
func newQueue(c clock.WithTicker, metrics queueMetrics, updatePeriod time.Duration) *Type {
|
||||||
t := &Type{
|
t := &Type{
|
||||||
clock: c,
|
clock: c,
|
||||||
dirty: set{},
|
dirty: set{},
|
||||||
@ -90,7 +90,7 @@ type Type struct {
|
|||||||
metrics queueMetrics
|
metrics queueMetrics
|
||||||
|
|
||||||
unfinishedWorkUpdatePeriod time.Duration
|
unfinishedWorkUpdatePeriod time.Duration
|
||||||
clock clock.Clock
|
clock clock.WithTicker
|
||||||
}
|
}
|
||||||
|
|
||||||
type empty struct{}
|
type empty struct{}
|
||||||
|
@ -20,13 +20,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
testingclock "k8s.io/utils/clock/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRateLimitingQueue(t *testing.T) {
|
func TestRateLimitingQueue(t *testing.T) {
|
||||||
limiter := NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Second)
|
limiter := NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1*time.Second)
|
||||||
queue := NewRateLimitingQueue(limiter).(*rateLimitingType)
|
queue := NewRateLimitingQueue(limiter).(*rateLimitingType)
|
||||||
fakeClock := clock.NewFakeClock(time.Now())
|
fakeClock := testingclock.NewFakeClock(time.Now())
|
||||||
delayingQueue := &delayingType{
|
delayingQueue := &delayingType{
|
||||||
Interface: New(),
|
Interface: New(),
|
||||||
clock: fakeClock,
|
clock: fakeClock,
|
||||||
|
Loading…
Reference in New Issue
Block a user