yangwwei commented on a change in pull request #173:
URL:
https://github.com/apache/incubator-yunikorn-core/pull/173#discussion_r450698683
##########
File path: pkg/scheduler/scheduling_queue_test.go
##########
@@ -688,11 +694,296 @@ func TestHeadroom(t *testing.T) {
res, err = resources.NewResourceFromConf(map[string]string{"first":
"10", "second": "2"})
assert.NilError(t, err, "failed to create resource")
headRoom = leaf1.getHeadRoom()
- if !resources.Equals(res, headRoom) {
+ maxHeadRoom = leaf1.getMaxHeadRoom()
+ if !resources.Equals(res, headRoom) || !resources.Equals(res,
maxHeadRoom) {
t.Errorf("leaf1 queue head room not as expected %v, got: %v
(err %v)", res, headRoom, err)
}
headRoom = leaf2.getHeadRoom()
+ maxHeadRoom = leaf2.getMaxHeadRoom()
+ if !resources.Equals(res, headRoom) || !resources.Equals(res,
maxHeadRoom) {
+ t.Errorf("leaf1 queue head room not as expected %v, got: %v
(err %v)", res, headRoom, err)
+ }
+}
+
+//nolint: funlen
+func TestMaxHeadroom(t *testing.T) {
+ // create the root: nil test
+ root, err := createRootQueue(nil)
+ assert.NilError(t, err, "queue create failed")
+ headRoom := root.getMaxHeadRoom()
+ if headRoom != nil {
+ t.Errorf("empty cluster with root queue should not have
headroom: %v", headRoom)
+ }
+
+ var parent *SchedulingQueue
+ // empty parent queue: nil test
+ parent, err = createManagedQueue(root, "parent", true, nil)
+ assert.NilError(t, err, "failed to create parent queue")
+ headRoom = parent.getMaxHeadRoom()
+ if headRoom != nil {
+ t.Errorf("empty cluster with parent queue should not have
headroom: %v", headRoom)
+ }
+
+ // recreate the structure, all queues have no max capacity set
+ // structure is:
+ // root (max: nil)
+ // - parent (max: nil)
+ // - leaf1 (max: nil) (alloc: 5,3)
+ // - leaf2 (max: nil) (alloc: 5,3)
+ root, err = createRootQueue(nil)
+ assert.NilError(t, err, "failed to create root queue with limit")
+ parent, err = createManagedQueue(root, "parent", true, nil)
+ assert.NilError(t, err, "failed to create parent queue")
+ var leaf1, leaf2 *SchedulingQueue
+ leaf1, err = createManagedQueue(parent, "leaf1", false, nil)
+ assert.NilError(t, err, "failed to create leaf1 queue")
+ leaf2, err = createManagedQueue(parent, "leaf2", false, nil)
+ assert.NilError(t, err, "failed to create leaf2 queue")
+
+ // allocating and allocated
+ var res *resources.Resource
+ res, err = resources.NewResourceFromConf(map[string]string{"first":
"1", "second": "1"})
+ assert.NilError(t, err, "failed to create resource")
+ leaf1.incAllocatingResource(res)
+ leaf2.incAllocatingResource(res)
+ res, err = resources.NewResourceFromConf(map[string]string{"first":
"4", "second": "2"})
+ assert.NilError(t, err, "failed to create resource")
+ err = leaf1.QueueInfo.IncAllocatedResource(res, true)
+ assert.NilError(t, err, "failed to set allocated resource on leaf1")
+ err = leaf2.QueueInfo.IncAllocatedResource(res, true)
+ assert.NilError(t, err, "failed to set allocated resource on leaf2")
+
+ headRoom = root.getMaxHeadRoom()
+ assert.Assert(t, headRoom == nil, "headRoom of root should be nil
because no max set for all queues")
+
+ headRoom = parent.getMaxHeadRoom()
+ assert.Assert(t, headRoom == nil, "headRoom of parent should be nil
because no max set for all queues")
+
+ headRoom = leaf1.getMaxHeadRoom()
+ assert.Assert(t, headRoom == nil, "headRoom of leaf1 should be nil
because no max set for all queues")
+
+ headRoom = leaf2.getMaxHeadRoom()
+ assert.Assert(t, headRoom == nil, "headRoom of leaf2 should be nil
because no max set for all queues")
+
+ // recreate the structure, set max capacity only in parent level
+ // structure is:
+ // root (max: nil)
+ // - parent (max: 20,8)
+ // - leaf1 (max: nil) (alloc: 5,3)
+ // - leaf2 (max: nil) (alloc: 6,4)
+ root, err = createRootQueue(nil)
+ resMap := map[string]string{"first": "20", "second": "8"}
+ assert.NilError(t, err, "failed to create root queue with limit")
+ parent, err = createManagedQueue(root, "parent", true, resMap)
+ assert.NilError(t, err, "failed to create parent queue")
+ leaf1, err = createManagedQueue(parent, "leaf1", false, nil)
+ assert.NilError(t, err, "failed to create leaf1 queue")
+ leaf2, err = createManagedQueue(parent, "leaf2", false, nil)
+ assert.NilError(t, err, "failed to create leaf2 queue")
+
+ // allocating and allocated
+ res, err = resources.NewResourceFromConf(map[string]string{"first":
"1", "second": "1"})
+ assert.NilError(t, err, "failed to create resource")
+ leaf1.incAllocatingResource(res)
+ leaf2.incAllocatingResource(res)
+ leaf2.incAllocatingResource(res)
+ res, err = resources.NewResourceFromConf(map[string]string{"first":
"4", "second": "2"})
+ assert.NilError(t, err, "failed to create resource")
+ err = leaf1.QueueInfo.IncAllocatedResource(res, true)
+ assert.NilError(t, err, "failed to set allocated resource on leaf1")
+ err = leaf2.QueueInfo.IncAllocatedResource(res, true)
+ assert.NilError(t, err, "failed to set allocated resource on leaf2")
+
+ // root headroom should be nil
+ headRoom = root.getMaxHeadRoom()
+ assert.Assert(t, headRoom == nil, "headRoom of root should be nil
because no max set for all queues")
+
+ // parent headroom = parentMax - leaf1Allocated - leaf2Allocated
+ // parent headroom = (20 - 5 - 6, 8 - 3 - 4) = (9, 1)
+ res, err = resources.NewResourceFromConf(map[string]string{"first":
"9", "second": "1"})
+ headRoom = parent.getMaxHeadRoom()
+ if err != nil || !resources.Equals(res, headRoom) {
+ t.Errorf("parent queue head room not as expected %v, got: %v
(err %v)", res, headRoom, err)
+ }
+
+ // leaf1 headroom = parentMax - leaf1Allocated - leaf2Allocated
+ headRoom = leaf1.getMaxHeadRoom()
+ if !resources.Equals(res, headRoom) {
+ t.Errorf("leaf1 queue head room not as expected %v, got: %v
(err %v)", res, headRoom, err)
+ }
+
+ headRoom = leaf2.getMaxHeadRoom()
+ if !resources.Equals(res, headRoom) {
+ t.Errorf("leaf2 queue head room not as expected %v, got: %v
(err %v)", res, headRoom, err)
+ }
+
+ // recreate the structure, set max capacity in root level, verify that
will be ignored
+ // structure is:
+ // root (max: 1, 1)
+ // - parent (max: 20,8)
+ // - leaf1 (max: nil) (alloc: 5,3)
+ // - leaf2 (max: nil) (alloc: 6,4)
Review comment:
removed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]