From 9ede7db445ff799d78fae4c20d9558962573ede7 Mon Sep 17 00:00:00 2001 From: Sachin Gopala Krishna Date: Tue, 11 Oct 2022 09:09:00 -0400 Subject: [PATCH] cpumanager policy static test refactor This refactors the tests which were breaking due to changes in isolated CPUs and reserved CPUs. Signed-off-by: Sachin Gopala Krishna --- pkg/kubelet/cm/cpumanager/cpu_manager_test.go | 11 ++++++++--- pkg/kubelet/cm/cpumanager/policy_static_test.go | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/kubelet/cm/cpumanager/cpu_manager_test.go b/pkg/kubelet/cm/cpumanager/cpu_manager_test.go index 31e4d0585fb..87c4ae036ca 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_manager_test.go +++ b/pkg/kubelet/cm/cpumanager/cpu_manager_test.go @@ -715,6 +715,8 @@ func TestCPUManagerRemove(t *testing.T) { } func TestReconcileState(t *testing.T) { + testExcl := false + testDM, _ := devicemanager.NewManagerStub() testPolicy, _ := NewStaticPolicy( &topology.CPUTopology{ NumCPUs: 8, @@ -733,8 +735,11 @@ func TestReconcileState(t *testing.T) { }, 0, cpuset.NewCPUSet(), + cpuset.NewCPUSet(), topologymanager.NewFakeManager(), - nil) + nil, + testDM, + testExcl) testCases := []struct { description string @@ -1369,8 +1374,8 @@ func TestCPUManagerHandlePolicyOptions(t *testing.T) { t.Errorf("cannot create state file: %s", err.Error()) } defer os.RemoveAll(sDir) - - _, err = NewManager(testCase.cpuPolicyName, testCase.cpuPolicyOptions, 5*time.Second, machineInfo, cpuset.NewCPUSet(), nodeAllocatableReservation, sDir, topologymanager.NewFakeManager()) + testDM, err := devicemanager.NewManagerStub() + _, err = NewManager(testCase.cpuPolicyName, testCase.cpuPolicyOptions, 5*time.Second, machineInfo, cpuset.NewCPUSet(), nodeAllocatableReservation, sDir, topologymanager.NewFakeManager(), testDM) if err == nil { t.Errorf("Expected error, but NewManager succeeded") } diff --git a/pkg/kubelet/cm/cpumanager/policy_static_test.go b/pkg/kubelet/cm/cpumanager/policy_static_test.go index 39aaaf95b28..d0308556c6d 100644 --- a/pkg/kubelet/cm/cpumanager/policy_static_test.go +++ b/pkg/kubelet/cm/cpumanager/policy_static_test.go @@ -202,7 +202,6 @@ func TestStaticPolicyAdd(t *testing.T) { largeTopoCPUSet := largeTopoBuilder.Result() largeTopoSock0CPUSet := largeTopoSock0Builder.Result() largeTopoSock1CPUSet := largeTopoSock1Builder.Result() - testDM, _ := devicemanager.NewManagerStub() // these are the cases which must behave the same regardless the policy options. // So we will permutate the options to ensure this holds true. optionsInsensitiveTestCases := []staticPolicyTest{ @@ -576,6 +575,8 @@ func runStaticPolicyTestCase(t *testing.T, testCase staticPolicyTest) { } func TestStaticPolicyReuseCPUs(t *testing.T) { + excludeReserved := false + testDM, _ := devicemanager.NewManagerStub() testCases := []struct { staticPolicyTest expCSetAfterAlloc cpuset.CPUSet @@ -692,7 +693,7 @@ func TestStaticPolicyRemove(t *testing.T) { } for _, testCase := range testCases { - policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.NewCPUSet(), topologymanager.NewFakeManager(), nil) + policy, _ := NewStaticPolicy(testCase.topo, testCase.numReservedCPUs, cpuset.NewCPUSet(), cpuset.NewCPUSet(), topologymanager.NewFakeManager(), nil, testDM, excludeReserved) st := &mockState{ assignments: testCase.stAssignments, -- 2.25.1