Skip to content

Commit 07283a2

Browse files
committed
Add test coverage
1 parent 1b3f0b8 commit 07283a2

2 files changed

Lines changed: 142 additions & 0 deletions

File tree

pkg/scheduler/objects/queue_test.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,3 +3051,104 @@ func TestQueueBackoffProperties(t *testing.T) {
30513051
assert.Equal(t, uint64(0), leaf3.GetMaxAppUnschedAskBackoff())
30523052
assert.Equal(t, 30*time.Second, leaf3.GetBackoffDelay())
30533053
}
3054+
3055+
func TestGetSchedulingOrder(t *testing.T) {
3056+
// create the root
3057+
root, err := createRootQueue(nil)
3058+
root.sortType = policies.FifoSortPolicy
3059+
assert.NilError(t, err, "queue create failed")
3060+
3061+
// setup queue hierarchy
3062+
parent1, err := createManagedQueue(root, "parent1", true, nil)
3063+
parent1.sortType = policies.FifoSortPolicy
3064+
assert.NilError(t, err, "failed to create parent1 queue")
3065+
parent2, err := createManagedQueue(root, "parent2", true, nil)
3066+
assert.NilError(t, err, "failed to create parent2 queue")
3067+
3068+
leaf1, err := createManagedQueue(parent1, "leaf1", false, nil)
3069+
assert.NilError(t, err, "failed to create leaf1 queue")
3070+
leaf2, err := createManagedQueue(parent1, "leaf2", false, nil)
3071+
assert.NilError(t, err, "failed to create leaf2 queue")
3072+
leaf3, err := createManagedQueue(parent2, "leaf3", false, nil)
3073+
assert.NilError(t, err, "failed to create leaf3 queue")
3074+
3075+
// resource for asks
3076+
res, err := resources.NewResourceFromConf(map[string]string{"first": "1"})
3077+
assert.NilError(t, err, "failed to create basic resource")
3078+
3079+
// App1 in leaf1 with pending resources
3080+
app1 := newApplication("app1", "default", leaf1.QueuePath)
3081+
app1.queue = leaf1
3082+
leaf1.AddApplication(app1)
3083+
err = app1.AddAllocationAsk(newAllocationAsk("alloc-1", "app1", res))
3084+
assert.NilError(t, err, "failed to add allocation ask to app1")
3085+
leaf1.incPendingResource(res)
3086+
3087+
// App2 in leaf1 with no pending resources
3088+
app2 := newApplication("app2", "default", leaf1.QueuePath)
3089+
app2.queue = leaf1
3090+
leaf1.AddApplication(app2)
3091+
3092+
// App3 in leaf2 with pending resources
3093+
app3 := newApplication("app3", "default", leaf2.QueuePath)
3094+
app3.queue = leaf2
3095+
leaf2.AddApplication(app3)
3096+
err = app3.AddAllocationAsk(newAllocationAsk("alloc-3", "app3", res))
3097+
assert.NilError(t, err, "failed to add allocation ask to app3")
3098+
leaf2.incPendingResource(res)
3099+
3100+
// App4 in leaf3 with pending resources, but cannot run
3101+
app4 := newApplication("app4", "default", leaf3.QueuePath)
3102+
app4.queue = leaf3
3103+
leaf3.AddApplication(app4)
3104+
err = app4.AddAllocationAsk(newAllocationAsk("alloc-4", "app4", res))
3105+
assert.NilError(t, err, "failed to add allocation ask to app4")
3106+
leaf3.incPendingResource(res)
3107+
// Make app4 not runnable by setting queue to full
3108+
leaf3.maxRunningApps = 1
3109+
leaf3.runningApps = 1
3110+
3111+
// Get scheduling order from root
3112+
order := root.GetSchedulingOrder()
3113+
3114+
// Expected order based on FIFO:
3115+
// 1. parent1 -> leaf1 (app1)
3116+
// 2. parent1 -> leaf2 (app3)
3117+
// 3. parent2 -> leaf3 (no apps, because app4 is not runnable but queue has pending)
3118+
assert.Equal(t, len(order), 3, "incorrect number of scheduling order entries")
3119+
3120+
// Entry 1: leaf1
3121+
assert.Equal(t, order[0].QueueName, "root.parent1.leaf1")
3122+
assert.Equal(t, len(order[0].ApplicationIDs), 1, "leaf1 should have one app")
3123+
assert.Equal(t, order[0].ApplicationIDs[0], "app1")
3124+
3125+
// Entry 2: leaf2
3126+
assert.Equal(t, order[1].QueueName, "root.parent1.leaf2")
3127+
assert.Equal(t, len(order[1].ApplicationIDs), 1, "leaf2 should have one app")
3128+
assert.Equal(t, order[1].ApplicationIDs[0], "app3")
3129+
3130+
// Entry 3: leaf3
3131+
assert.Equal(t, order[2].QueueName, "root.parent2.leaf3")
3132+
assert.Equal(t, len(order[2].ApplicationIDs), 0, "leaf3 should have no runnable apps")
3133+
3134+
// Test a leaf queue directly
3135+
order = leaf1.GetSchedulingOrder()
3136+
assert.Equal(t, len(order), 1, "direct call on leaf1 failed")
3137+
assert.Equal(t, order[0].QueueName, "root.parent1.leaf1")
3138+
assert.Equal(t, len(order[0].ApplicationIDs), 1)
3139+
assert.Equal(t, order[0].ApplicationIDs[0], "app1")
3140+
3141+
// Test a leaf queue with no pending resources
3142+
leaf4, err := createManagedQueue(parent2, "leaf4", false, nil)
3143+
assert.NilError(t, err, "failed to create leaf4")
3144+
order = leaf4.GetSchedulingOrder()
3145+
assert.Equal(t, len(order), 0, "leaf queue with no pending resources should return nil/empty")
3146+
3147+
// Test a parent with no pending children
3148+
parent3, err := createManagedQueue(root, "parent3", true, nil)
3149+
assert.NilError(t, err, "failed to create parent3")
3150+
_, err = createManagedQueue(parent3, "leaf5", false, nil)
3151+
assert.NilError(t, err, "failed to create leaf5")
3152+
order = parent3.GetSchedulingOrder()
3153+
assert.Equal(t, len(order), 0, "parent with no pending children should return empty")
3154+
}

pkg/scheduler/partition_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4957,3 +4957,44 @@ func TestApplicationBackoff(t *testing.T) {
49574957
assert.Assert(t, !deadline.IsZero())
49584958
assert.Assert(t, deadline.After(beforeAlloc))
49594959
}
4960+
4961+
func TestGetPartitionQueueDAOInfo(t *testing.T) {
4962+
conf := configs.PartitionConfig{
4963+
Name: "default",
4964+
Queues: []configs.QueueConfig{
4965+
{
4966+
Name: "root",
4967+
Parent: true,
4968+
SubmitACL: "*",
4969+
Queues: []configs.QueueConfig{
4970+
{
4971+
Name: "parent",
4972+
Parent: true,
4973+
Queues: []configs.QueueConfig{
4974+
{
4975+
Name: "leaf",
4976+
Parent: false,
4977+
},
4978+
},
4979+
},
4980+
},
4981+
},
4982+
},
4983+
}
4984+
partition, err := newPartitionContext(conf, "test-rm", nil, true)
4985+
assert.NilError(t, err, "partition create failed")
4986+
4987+
daoInfo := partition.GetPartitionQueues()
4988+
4989+
assert.Equal(t, "default", daoInfo.Partition)
4990+
assert.Equal(t, "root", daoInfo.QueueName)
4991+
assert.Equal(t, 1, len(daoInfo.Children))
4992+
4993+
parentDAO := daoInfo.Children[0]
4994+
assert.Equal(t, "root.parent", parentDAO.QueueName)
4995+
assert.Equal(t, 1, len(parentDAO.Children))
4996+
4997+
leafDAO := parentDAO.Children[0]
4998+
assert.Equal(t, "root.parent.leaf", leafDAO.QueueName)
4999+
assert.Equal(t, 0, len(leafDAO.Children))
5000+
}

0 commit comments

Comments
 (0)