Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: test file use k8s.io/utils/clock instead #105375

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions pkg/controller/nodelifecycle/scheduler/timed_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (

"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
// TODO: Switch to k8s.io/utils/clock once it supports AfterFunc()
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
)

// WorkArgs keeps arguments that will be passed to the function executed by the worker.
Expand All @@ -50,7 +49,7 @@ type TimedWorker struct {
}

// createWorker creates a TimedWorker that will execute `f` not earlier than `fireAt`.
func createWorker(args *WorkArgs, createdAt time.Time, fireAt time.Time, f func(args *WorkArgs) error, clock clock.Clock) *TimedWorker {
func createWorker(args *WorkArgs, createdAt time.Time, fireAt time.Time, f func(args *WorkArgs) error, clock clock.WithDelayedExecution) *TimedWorker {
delay := fireAt.Sub(createdAt)
if delay <= 0 {
go f(args)
Expand Down Expand Up @@ -78,7 +77,7 @@ type TimedWorkerQueue struct {
// map of workers keyed by string returned by 'KeyFromWorkArgs' from the given worker.
workers map[string]*TimedWorker
workFunc func(args *WorkArgs) error
clock clock.Clock
clock clock.WithDelayedExecution
}

// CreateWorkerQueue creates a new TimedWorkerQueue for workers that will execute
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/nodelifecycle/scheduler/timed_workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"
"time"

"k8s.io/apimachinery/pkg/util/clock"
testingclock "k8s.io/utils/clock/testing"
)

func TestExecute(t *testing.T) {
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestExecuteDelayed(t *testing.T) {
})
now := time.Now()
then := now.Add(10 * time.Second)
fakeClock := clock.NewFakeClock(now)
fakeClock := testingclock.NewFakeClock(now)
queue.clock = fakeClock
queue.AddWork(NewWorkArgs("1", "1"), now, then)
queue.AddWork(NewWorkArgs("2", "2"), now, then)
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestCancel(t *testing.T) {
})
now := time.Now()
then := now.Add(10 * time.Second)
fakeClock := clock.NewFakeClock(now)
fakeClock := testingclock.NewFakeClock(now)
queue.clock = fakeClock
queue.AddWork(NewWorkArgs("1", "1"), now, then)
queue.AddWork(NewWorkArgs("2", "2"), now, then)
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestCancelAndReadd(t *testing.T) {
})
now := time.Now()
then := now.Add(10 * time.Second)
fakeClock := clock.NewFakeClock(now)
fakeClock := testingclock.NewFakeClock(now)
queue.clock = fakeClock
queue.AddWork(NewWorkArgs("1", "1"), now, then)
queue.AddWork(NewWorkArgs("2", "2"), now, then)
Expand Down
1 change: 0 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,6 @@ k8s.io/apimachinery/pkg/runtime/serializer/yaml
k8s.io/apimachinery/pkg/selection
k8s.io/apimachinery/pkg/types
k8s.io/apimachinery/pkg/util/cache
k8s.io/apimachinery/pkg/util/clock
k8s.io/apimachinery/pkg/util/diff
k8s.io/apimachinery/pkg/util/duration
k8s.io/apimachinery/pkg/util/errors
Expand Down