Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ test case matrix.

func Test_getPodUsage(t *testing.T) {
s := NewScheduler()
t.Cleanup(s.Stop)
client.KubeClient = fake.NewClientset()
s.kubeClient = client.KubeClient
informerFactory := informers.NewSharedInformerFactoryWithOptions(client.KubeClient, time.Hour*1)
Expand Down Expand Up @@ -476,6 +477,7 @@ test case matrix.
*/
func Test_Filter(t *testing.T) {
s := NewScheduler()
t.Cleanup(s.Stop)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@v0idheaven I test this PR with the following commands

go test ./pkg/scheduler/ \
      -run '^(Test_Filter|Test_onAddPod_BadDeviceAnnotation)$' \
      -count=1 -race

And here comes an error

E0809 23:37:49.760989  973437 scheduler.go:162] "failed to decode pod devices" err="pod annotation format error, missing fields, do not use nodeName in task spec" pod="default/bad-anno-pod"
--- FAIL: Test_onAddPod_BadDeviceAnnotation (0.00s)
    testing.go:1712: race detected during execution of test

Is this an expected error?

client.KubeClient = fake.NewClientset()
s.kubeClient = client.KubeClient
informerFactory := informers.NewSharedInformerFactoryWithOptions(client.KubeClient, time.Hour*1)
Expand Down Expand Up @@ -1042,7 +1044,6 @@ func Test_RegisterFromNodeAnnotations(t *testing.T) {
name: "test node handshake annotations layout",
Scheduler: func() *Scheduler {
s := NewScheduler()
s.stopCh = make(chan struct{})
s.nodeNotify = make(chan struct{})
client.KubeClient = fake.NewClientset()
s.kubeClient = client.KubeClient
Expand Down Expand Up @@ -1136,7 +1137,6 @@ func Test_RegisterFromNodeAnnotations_NIL(t *testing.T) {
// Define a helper function to create a scheduler with a node that has nil annotations.
createSchedulerWithNilAnnotations := func() *Scheduler {
s := NewScheduler()
s.stopCh = make(chan struct{})
s.nodeNotify = make(chan struct{})

client.KubeClient = fake.NewClientset()
Expand Down Expand Up @@ -1309,7 +1309,6 @@ func TestRegisterSkipsCleanupForUntrackedVendor(t *testing.T) {
}

s := NewScheduler()
s.stopCh = make(chan struct{})
client.KubeClient = fake.NewClientset()
s.kubeClient = client.KubeClient

Expand Down Expand Up @@ -1346,6 +1345,7 @@ func TestRegisterSkipsCleanupForUntrackedVendor(t *testing.T) {

informerFactory.Start(s.stopCh)
informerFactory.WaitForCacheSync(s.stopCh)
t.Cleanup(s.Stop)

s.addNode("node-1", &device.NodeInfo{
ID: "node-1",
Expand Down Expand Up @@ -1379,6 +1379,7 @@ func TestRegisterSkipsCleanupForUntrackedVendor(t *testing.T) {

func Test_ResourceQuota(t *testing.T) {
s := NewScheduler()
t.Cleanup(s.Stop)
client.KubeClient = fake.NewClientset()
s.kubeClient = client.KubeClient
informerFactory := informers.NewSharedInformerFactoryWithOptions(client.KubeClient, time.Hour*1)
Expand Down Expand Up @@ -2094,6 +2095,7 @@ func Test_Bind_DelPodOnGetPodFailure(t *testing.T) {
}

s := NewScheduler()
t.Cleanup(s.Stop)
scheme := runtime.NewScheme()
_ = corev1.AddToScheme(scheme)
s.eventRecorder = record.NewBroadcaster().NewRecorder(scheme, corev1.EventSource{})
Expand Down Expand Up @@ -2137,6 +2139,7 @@ func Test_Bind_DelPodOnGetNodeFailure(t *testing.T) {
}

s := NewScheduler()
t.Cleanup(s.Stop)
scheme := runtime.NewScheme()
_ = corev1.AddToScheme(scheme)
s.eventRecorder = record.NewBroadcaster().NewRecorder(scheme, corev1.EventSource{})
Expand Down Expand Up @@ -2210,11 +2213,6 @@ func setupBindLockRetryTest(t *testing.T, retryTimeout time.Duration, pod *corev
device.DevicesMap = map[string]device.Devices{"bind-lock-mock": mock}

s := NewScheduler()
cleanup := func() {
config.NodeLockRetryTimeout = oldRetry
device.DevicesMap = oldDevicesMap
close(s.stopCh)
}
scheme := runtime.NewScheme()
_ = corev1.AddToScheme(scheme)
s.eventRecorder = record.NewBroadcaster().NewRecorder(scheme, corev1.EventSource{})
Expand All @@ -2225,6 +2223,11 @@ func setupBindLockRetryTest(t *testing.T, retryTimeout time.Duration, pod *corev
client.KubeClient = fakeClient

informerFactory := informers.NewSharedInformerFactoryWithOptions(fakeClient, time.Hour)
cleanup := func() {
config.NodeLockRetryTimeout = oldRetry
device.DevicesMap = oldDevicesMap
s.Stop()
}
require.NoError(t, informerFactory.Core().V1().Pods().Informer().GetIndexer().Add(pod))
require.NoError(t, informerFactory.Core().V1().Nodes().Informer().GetIndexer().Add(node))
s.podLister = informerFactory.Core().V1().Pods().Lister()
Expand Down
Loading