...
1
16
17 package topologymanager
18
19 import (
20 "testing"
21 )
22
23 func TestPolicyRestrictedName(t *testing.T) {
24 tcases := []struct {
25 name string
26 expected string
27 }{
28 {
29 name: "New Restricted Policy",
30 expected: "restricted",
31 },
32 }
33 numaInfo := commonNUMAInfoTwoNodes()
34 for _, tc := range tcases {
35 policy := &restrictedPolicy{bestEffortPolicy{numaInfo: numaInfo, opts: PolicyOptions{}}}
36 if policy.Name() != tc.expected {
37 t.Errorf("Expected Policy Name to be %s, got %s", tc.expected, policy.Name())
38 }
39 }
40 }
41
42 func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) {
43 tcases := []struct {
44 name string
45 hint TopologyHint
46 expected bool
47 }{
48 {
49 name: "Preferred is set to false in topology hints",
50 hint: TopologyHint{nil, false},
51 expected: false,
52 },
53 {
54 name: "Preferred is set to true in topology hints",
55 hint: TopologyHint{nil, true},
56 expected: true,
57 },
58 }
59
60 for _, tc := range tcases {
61 numaInfo := commonNUMAInfoTwoNodes()
62 policy := &restrictedPolicy{bestEffortPolicy{numaInfo: numaInfo}}
63 result := policy.canAdmitPodResult(&tc.hint)
64
65 if result != tc.expected {
66 t.Errorf("Expected result to be %t, got %t", tc.expected, result)
67 }
68 }
69 }
70
71 func TestPolicyRestrictedMerge(t *testing.T) {
72 numaInfo := commonNUMAInfoFourNodes()
73 policy := &restrictedPolicy{bestEffortPolicy{numaInfo: numaInfo}}
74
75 tcases := commonPolicyMergeTestCases(numaInfo.Nodes)
76 tcases = append(tcases, policy.mergeTestCases(numaInfo.Nodes)...)
77 tcases = append(tcases, policy.mergeTestCasesNoPolicies(numaInfo.Nodes)...)
78
79 testPolicyMerge(policy, tcases, t)
80 }
81
82 func TestPolicyRestrictedMergeClosestNUMA(t *testing.T) {
83 numaInfo := commonNUMAInfoEightNodes()
84 policy := &restrictedPolicy{bestEffortPolicy{numaInfo: numaInfo, opts: PolicyOptions{PreferClosestNUMA: true}}}
85
86 tcases := commonPolicyMergeTestCases(numaInfo.Nodes)
87 tcases = append(tcases, policy.mergeTestCases(numaInfo.Nodes)...)
88 tcases = append(tcases, policy.mergeTestCasesClosestNUMA(numaInfo.Nodes)...)
89
90 testPolicyMerge(policy, tcases, t)
91 }
92
View as plain text