mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 16:49:35 +00:00
Update topologymanager tests after adding scopes
Signed-off-by: Krzysztof Wiatrzyk <k.wiatrzyk@samsung.com>
This commit is contained in:
parent
9da0912a33
commit
f5c0fe4ef6
@ -75,8 +75,6 @@ func TestFakeAddContainer(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
fm := fakeManager{}
|
fm := fakeManager{}
|
||||||
mngr := manager{}
|
|
||||||
mngr.podMap = make(map[string]string)
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
pod := v1.Pod{}
|
pod := v1.Pod{}
|
||||||
pod.UID = tc.podUID
|
pod.UID = tc.podUID
|
||||||
@ -107,8 +105,6 @@ func TestFakeRemoveContainer(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
fm := fakeManager{}
|
fm := fakeManager{}
|
||||||
mngr := manager{}
|
|
||||||
mngr.podMap = make(map[string]string)
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
err := fm.RemoveContainer(tc.containerID)
|
err := fm.RemoveContainer(tc.containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -147,8 +143,6 @@ func TestFakeAdmit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fm := fakeManager{}
|
fm := fakeManager{}
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
mngr := manager{}
|
|
||||||
mngr.podTopologyHints = make(map[string]map[string]TopologyHint)
|
|
||||||
podAttr := lifecycle.PodAdmitAttributes{}
|
podAttr := lifecycle.PodAdmitAttributes{}
|
||||||
pod := v1.Pod{}
|
pod := v1.Pod{}
|
||||||
pod.Status.QOSClass = tc.qosClass
|
pod.Status.QOSClass = tc.qosClass
|
||||||
|
@ -40,6 +40,11 @@ func TestNewManager(t *testing.T) {
|
|||||||
expectedPolicy string
|
expectedPolicy string
|
||||||
expectedError error
|
expectedError error
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
description: "Policy is set to none",
|
||||||
|
policyName: "none",
|
||||||
|
expectedPolicy: "none",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Policy is set to best-effort",
|
description: "Policy is set to best-effort",
|
||||||
policyName: "best-effort",
|
policyName: "best-effort",
|
||||||
@ -50,6 +55,11 @@ func TestNewManager(t *testing.T) {
|
|||||||
policyName: "restricted",
|
policyName: "restricted",
|
||||||
expectedPolicy: "restricted",
|
expectedPolicy: "restricted",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Policy is set to single-numa-node",
|
||||||
|
policyName: "single-numa-node",
|
||||||
|
expectedPolicy: "single-numa-node",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Policy is set to unknown",
|
description: "Policy is set to unknown",
|
||||||
policyName: "unknown",
|
policyName: "unknown",
|
||||||
@ -58,7 +68,7 @@ func TestNewManager(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
mngr, err := NewManager(nil, tc.policyName)
|
mngr, err := NewManager(nil, tc.policyName, "container")
|
||||||
|
|
||||||
if tc.expectedError != nil {
|
if tc.expectedError != nil {
|
||||||
if !strings.Contains(err.Error(), tc.expectedError.Error()) {
|
if !strings.Contains(err.Error(), tc.expectedError.Error()) {
|
||||||
@ -66,8 +76,49 @@ func TestNewManager(t *testing.T) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rawMgr := mngr.(*manager)
|
rawMgr := mngr.(*manager)
|
||||||
if rawMgr.policy.Name() != tc.expectedPolicy {
|
rawScope := rawMgr.scope.(*containerScope)
|
||||||
t.Errorf("Unexpected policy name. Have: %q wants %q", rawMgr.policy.Name(), tc.expectedPolicy)
|
if rawScope.policy.Name() != tc.expectedPolicy {
|
||||||
|
t.Errorf("Unexpected policy name. Have: %q wants %q", rawScope.policy.Name(), tc.expectedPolicy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestManagerScope(t *testing.T) {
|
||||||
|
tcases := []struct {
|
||||||
|
description string
|
||||||
|
scopeName string
|
||||||
|
expectedScope string
|
||||||
|
expectedError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "Topology Manager Scope is set to container",
|
||||||
|
scopeName: "container",
|
||||||
|
expectedScope: "container",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "Topology Manager Scope is set to pod",
|
||||||
|
scopeName: "pod",
|
||||||
|
expectedScope: "pod",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "Topology Manager Scope is set to unknown",
|
||||||
|
scopeName: "unknown",
|
||||||
|
expectedError: fmt.Errorf("unknown scope: \"unknown\""),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tcases {
|
||||||
|
mngr, err := NewManager(nil, "best-effort", tc.scopeName)
|
||||||
|
|
||||||
|
if tc.expectedError != nil {
|
||||||
|
if !strings.Contains(err.Error(), tc.expectedError.Error()) {
|
||||||
|
t.Errorf("Unexpected error message. Have: %s wants %s", err.Error(), tc.expectedError.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rawMgr := mngr.(*manager)
|
||||||
|
if rawMgr.scope.Name() != tc.expectedScope {
|
||||||
|
t.Errorf("Unexpected scope name. Have: %q wants %q", rawMgr.scope, tc.expectedScope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,7 +485,6 @@ func TestRemoveContainer(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
func TestAddHintProvider(t *testing.T) {
|
func TestAddHintProvider(t *testing.T) {
|
||||||
var len1 int
|
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
hp []HintProvider
|
hp []HintProvider
|
||||||
@ -443,18 +493,20 @@ func TestAddHintProvider(t *testing.T) {
|
|||||||
name: "Add HintProvider",
|
name: "Add HintProvider",
|
||||||
hp: []HintProvider{
|
hp: []HintProvider{
|
||||||
&mockHintProvider{},
|
&mockHintProvider{},
|
||||||
|
&mockHintProvider{},
|
||||||
|
&mockHintProvider{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
mngr := manager{}
|
mngr := manager{}
|
||||||
|
mngr.scope = NewContainerScope(NewNonePolicy())
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
mngr.hintProviders = []HintProvider{}
|
for _, hp := range tc.hp {
|
||||||
len1 = len(mngr.hintProviders)
|
mngr.AddHintProvider(hp)
|
||||||
mngr.AddHintProvider(tc.hp[0])
|
}
|
||||||
}
|
if len(tc.hp) != len(mngr.scope.(*containerScope).hintProviders) {
|
||||||
len2 := len(mngr.hintProviders)
|
t.Errorf("error")
|
||||||
if len2-len1 != 1 {
|
}
|
||||||
t.Errorf("error")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,11 +779,13 @@ func TestAdmit(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
man := manager{
|
ctnScopeManager := manager{}
|
||||||
policy: tc.policy,
|
ctnScopeManager.scope = NewContainerScope(tc.policy)
|
||||||
podTopologyHints: make(map[string]map[string]TopologyHint),
|
ctnScopeManager.scope.(*containerScope).hintProviders = tc.hp
|
||||||
hintProviders: tc.hp,
|
|
||||||
}
|
podScopeManager := manager{}
|
||||||
|
podScopeManager.scope = NewPodScope(tc.policy)
|
||||||
|
podScopeManager.scope.(*podScope).hintProviders = tc.hp
|
||||||
|
|
||||||
pod := &v1.Pod{
|
pod := &v1.Pod{
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
@ -750,9 +804,16 @@ func TestAdmit(t *testing.T) {
|
|||||||
Pod: pod,
|
Pod: pod,
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := man.Admit(&podAttr)
|
// Container scope Admit
|
||||||
if actual.Admit != tc.expected {
|
ctnActual := ctnScopeManager.Admit(&podAttr)
|
||||||
t.Errorf("Error occurred, expected Admit in result to be %v got %v", tc.expected, actual.Admit)
|
if ctnActual.Admit != tc.expected {
|
||||||
|
t.Errorf("Error occurred, expected Admit in result to be %v got %v", tc.expected, ctnActual.Admit)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pod scope Admit
|
||||||
|
podActual := podScopeManager.Admit(&podAttr)
|
||||||
|
if podActual.Admit != tc.expected {
|
||||||
|
t.Errorf("Error occurred, expected Admit in result to be %v got %v", tc.expected, podActual.Admit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user