mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 15:50:10 +00:00
CPU Manager - Updates to unit tests:
- Where previously we called manager.AddContainer(), we now call both manager.Allocate() and manager.AddContainer(). - Some test cases now have two expected errors. One each from Allocate() and AddContainer(). Existing outcomes are unchanged.
This commit is contained in:
parent
467f66580b
commit
0a9bd0334d
@ -227,14 +227,16 @@ func TestCPUManagerAdd(t *testing.T) {
|
|||||||
updateErr error
|
updateErr error
|
||||||
policy Policy
|
policy Policy
|
||||||
expCPUSet cpuset.CPUSet
|
expCPUSet cpuset.CPUSet
|
||||||
expErr error
|
expAllocateErr error
|
||||||
|
expAddContainerErr error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
description: "cpu manager add - no error",
|
description: "cpu manager add - no error",
|
||||||
updateErr: nil,
|
updateErr: nil,
|
||||||
policy: testPolicy,
|
policy: testPolicy,
|
||||||
expCPUSet: cpuset.NewCPUSet(3, 4),
|
expCPUSet: cpuset.NewCPUSet(3, 4),
|
||||||
expErr: nil,
|
expAllocateErr: nil,
|
||||||
|
expAddContainerErr: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "cpu manager add - policy add container error",
|
description: "cpu manager add - policy add container error",
|
||||||
@ -243,14 +245,16 @@ func TestCPUManagerAdd(t *testing.T) {
|
|||||||
err: fmt.Errorf("fake reg error"),
|
err: fmt.Errorf("fake reg error"),
|
||||||
},
|
},
|
||||||
expCPUSet: cpuset.NewCPUSet(1, 2, 3, 4),
|
expCPUSet: cpuset.NewCPUSet(1, 2, 3, 4),
|
||||||
expErr: fmt.Errorf("fake reg error"),
|
expAllocateErr: fmt.Errorf("fake reg error"),
|
||||||
|
expAddContainerErr: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "cpu manager add - container update error",
|
description: "cpu manager add - container update error",
|
||||||
updateErr: fmt.Errorf("fake update error"),
|
updateErr: fmt.Errorf("fake update error"),
|
||||||
policy: testPolicy,
|
policy: testPolicy,
|
||||||
expCPUSet: cpuset.NewCPUSet(1, 2, 3, 4),
|
expCPUSet: cpuset.NewCPUSet(1, 2, 3, 4),
|
||||||
expErr: fmt.Errorf("fake update error"),
|
expAllocateErr: nil,
|
||||||
|
expAddContainerErr: fmt.Errorf("fake update error"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,10 +275,16 @@ func TestCPUManagerAdd(t *testing.T) {
|
|||||||
|
|
||||||
pod := makePod("fakePod", "fakeContainer", "2", "2")
|
pod := makePod("fakePod", "fakeContainer", "2", "2")
|
||||||
container := &pod.Spec.Containers[0]
|
container := &pod.Spec.Containers[0]
|
||||||
err := mgr.AddContainer(pod, container, "fakeID")
|
err := mgr.Allocate(pod, container)
|
||||||
if !reflect.DeepEqual(err, testCase.expErr) {
|
if !reflect.DeepEqual(err, testCase.expAllocateErr) {
|
||||||
|
t.Errorf("CPU Manager Allocate() error (%v). expected error: %v but got: %v",
|
||||||
|
testCase.description, testCase.expAllocateErr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = mgr.AddContainer(pod, container, "fakeID")
|
||||||
|
if !reflect.DeepEqual(err, testCase.expAddContainerErr) {
|
||||||
t.Errorf("CPU Manager AddContainer() error (%v). expected error: %v but got: %v",
|
t.Errorf("CPU Manager AddContainer() error (%v). expected error: %v but got: %v",
|
||||||
testCase.description, testCase.expErr, err)
|
testCase.description, testCase.expAddContainerErr, err)
|
||||||
}
|
}
|
||||||
if !testCase.expCPUSet.Equals(mgr.state.GetDefaultCPUSet()) {
|
if !testCase.expCPUSet.Equals(mgr.state.GetDefaultCPUSet()) {
|
||||||
t.Errorf("CPU Manager AddContainer() error (%v). expected cpuset: %v but got: %v",
|
t.Errorf("CPU Manager AddContainer() error (%v). expected cpuset: %v but got: %v",
|
||||||
@ -494,7 +504,12 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
|
|||||||
testCase.expCSets...)
|
testCase.expCSets...)
|
||||||
|
|
||||||
for i := range containers {
|
for i := range containers {
|
||||||
err := mgr.AddContainer(testCase.pod, &containers[i], containerIDs[i])
|
err := mgr.Allocate(testCase.pod, &containers[i])
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("StaticPolicy Allocate() error (%v). unexpected error for container id: %v: %v",
|
||||||
|
testCase.description, containerIDs[i], err)
|
||||||
|
}
|
||||||
|
err = mgr.AddContainer(testCase.pod, &containers[i], containerIDs[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("StaticPolicy AddContainer() error (%v). unexpected error for container id: %v: %v",
|
t.Errorf("StaticPolicy AddContainer() error (%v). unexpected error for container id: %v: %v",
|
||||||
testCase.description, containerIDs[i], err)
|
testCase.description, containerIDs[i], err)
|
||||||
@ -974,21 +989,24 @@ func TestCPUManagerAddWithResvList(t *testing.T) {
|
|||||||
updateErr error
|
updateErr error
|
||||||
policy Policy
|
policy Policy
|
||||||
expCPUSet cpuset.CPUSet
|
expCPUSet cpuset.CPUSet
|
||||||
expErr error
|
expAllocateErr error
|
||||||
|
expAddContainerErr error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
description: "cpu manager add - no error",
|
description: "cpu manager add - no error",
|
||||||
updateErr: nil,
|
updateErr: nil,
|
||||||
policy: testPolicy,
|
policy: testPolicy,
|
||||||
expCPUSet: cpuset.NewCPUSet(0, 3),
|
expCPUSet: cpuset.NewCPUSet(0, 3),
|
||||||
expErr: nil,
|
expAllocateErr: nil,
|
||||||
|
expAddContainerErr: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "cpu manager add - container update error",
|
description: "cpu manager add - container update error",
|
||||||
updateErr: fmt.Errorf("fake update error"),
|
updateErr: fmt.Errorf("fake update error"),
|
||||||
policy: testPolicy,
|
policy: testPolicy,
|
||||||
expCPUSet: cpuset.NewCPUSet(0, 1, 2, 3),
|
expCPUSet: cpuset.NewCPUSet(0, 1, 2, 3),
|
||||||
expErr: fmt.Errorf("fake update error"),
|
expAllocateErr: nil,
|
||||||
|
expAddContainerErr: fmt.Errorf("fake update error"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,10 +1027,16 @@ func TestCPUManagerAddWithResvList(t *testing.T) {
|
|||||||
|
|
||||||
pod := makePod("fakePod", "fakeContainer", "2", "2")
|
pod := makePod("fakePod", "fakeContainer", "2", "2")
|
||||||
container := &pod.Spec.Containers[0]
|
container := &pod.Spec.Containers[0]
|
||||||
err := mgr.AddContainer(pod, container, "fakeID")
|
err := mgr.Allocate(pod, container)
|
||||||
if !reflect.DeepEqual(err, testCase.expErr) {
|
if !reflect.DeepEqual(err, testCase.expAllocateErr) {
|
||||||
|
t.Errorf("CPU Manager Allocate() error (%v). expected error: %v but got: %v",
|
||||||
|
testCase.description, testCase.expAllocateErr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = mgr.AddContainer(pod, container, "fakeID")
|
||||||
|
if !reflect.DeepEqual(err, testCase.expAddContainerErr) {
|
||||||
t.Errorf("CPU Manager AddContainer() error (%v). expected error: %v but got: %v",
|
t.Errorf("CPU Manager AddContainer() error (%v). expected error: %v but got: %v",
|
||||||
testCase.description, testCase.expErr, err)
|
testCase.description, testCase.expAddContainerErr, err)
|
||||||
}
|
}
|
||||||
if !testCase.expCPUSet.Equals(mgr.state.GetDefaultCPUSet()) {
|
if !testCase.expCPUSet.Equals(mgr.state.GetDefaultCPUSet()) {
|
||||||
t.Errorf("CPU Manager AddContainer() error (%v). expected cpuset: %v but got: %v",
|
t.Errorf("CPU Manager AddContainer() error (%v). expected cpuset: %v but got: %v",
|
||||||
|
Loading…
Reference in New Issue
Block a user