Skip to content

Commit 7a1a16d

Browse files
committed
[YUNIKORN-2948] [shim] Write MockScheduler test which verifies foreign pod tracking
1 parent be76576 commit 7a1a16d

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

pkg/shim/scheduler_mock_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,23 @@ func (fc *MockScheduler) waitForApplicationStateInCore(appID, partition, expecte
318318
}, time.Second, 5*time.Second)
319319
}
320320

321+
func (fc *MockScheduler) waitAndAssertForeignAllocationInCore(partition, allocationID, nodeID string, exists bool) error {
322+
return utils.WaitForCondition(func() bool {
323+
node := fc.coreContext.Scheduler.GetClusterContext().GetNode(nodeID, partition)
324+
if node == nil {
325+
return false
326+
}
327+
allocs := node.GetForeignAllocations()
328+
for _, alloc := range allocs {
329+
if alloc.GetAllocationKey() == allocationID && exists {
330+
return true
331+
}
332+
}
333+
334+
return !exists
335+
}, time.Second, 5*time.Second)
336+
}
337+
321338
func (fc *MockScheduler) getApplicationFromCore(appID, partition string) *objects.Application {
322339
return fc.coreContext.Scheduler.GetClusterContext().GetApplication(appID, partition)
323340
}

pkg/shim/scheduler_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,60 @@ partitions:
305305
assert.Equal(t, 0, len(app.GetAllAllocations()), "allocations were not removed from the application")
306306
}
307307

308+
func TestForeignPodTracking(t *testing.T) {
309+
configData := `
310+
partitions:
311+
- name: default
312+
queues:
313+
- name: root
314+
submitacl: "*"
315+
queues:
316+
- name: a
317+
resources:
318+
guaranteed:
319+
memory: 100000000
320+
vcore: 10
321+
max:
322+
memory: 150000000
323+
vcore: 20
324+
`
325+
cluster := MockScheduler{}
326+
cluster.init()
327+
assert.NilError(t, cluster.start(), "failed to start cluster")
328+
defer cluster.stop()
329+
330+
err := cluster.updateConfig(configData, nil)
331+
assert.NilError(t, err, "update config failed")
332+
addNode(&cluster, "node-1")
333+
334+
podResource := common.NewResourceBuilder().
335+
AddResource(siCommon.Memory, 1000).
336+
AddResource(siCommon.CPU, 1).
337+
Build()
338+
pod1 := createTestPod("root.a", "", "foreign-1", podResource)
339+
pod1.Spec.SchedulerName = ""
340+
pod1.Spec.NodeName = "node-1"
341+
pod2 := createTestPod("root.a", "", "foreign-2", podResource)
342+
pod2.Spec.SchedulerName = ""
343+
pod2.Spec.NodeName = "node-1"
344+
345+
cluster.AddPod(pod1)
346+
cluster.AddPod(pod2)
347+
348+
err = cluster.waitAndAssertForeignAllocationInCore(partitionName, "foreign-1", "node-1", true)
349+
assert.NilError(t, err)
350+
err = cluster.waitAndAssertForeignAllocationInCore(partitionName, "foreign-2", "node-1", true)
351+
assert.NilError(t, err)
352+
353+
cluster.DeletePod(pod1)
354+
cluster.DeletePod(pod2)
355+
356+
err = cluster.waitAndAssertForeignAllocationInCore(partitionName, "foreign-1", "node-1", false)
357+
assert.NilError(t, err)
358+
err = cluster.waitAndAssertForeignAllocationInCore(partitionName, "foreign-2", "node-1", false)
359+
assert.NilError(t, err)
360+
}
361+
308362
func createTestPod(queue string, appID string, taskID string, taskResource *si.Resource) *v1.Pod {
309363
containers := make([]v1.Container, 0)
310364
c1Resources := make(map[v1.ResourceName]resource.Quantity)

0 commit comments

Comments
 (0)