Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2998] tryNodesNoReserve is not tested #1008

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkg/scheduler/objects/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3596,3 +3596,48 @@ func TestTryPlaceHolderAllocateDifferentNodes(t *testing.T) {
// placeholder data remains unchanged until RM confirms the replacement
assertPlaceholderData(t, app, tg1, 1, 0, 0, res)
}

func TestTryNodesNoReserve(t *testing.T) {
app := newApplication(appID0, "default", "root.default")

queue, err := createRootQueue(map[string]string{"first": "5"})
assert.NilError(t, err, "queue create failed")
app.queue = queue

res := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5})
ask := newAllocationAsk(aKey, appID0, res)
err = app.AddAllocationAsk(ask)
assert.NilError(t, err, "ask should have been added to app")

// reserve the allocation on node1
node1 := newNode(nodeID1, map[string]resources.Quantity{"first": 5})
err = app.Reserve(node1, ask)
assert.NilError(t, err, "reservation failed")

// case 1: node is the reserved node
iterator := getNodeIteratorFn(node1)
result := app.tryNodesNoReserve(ask, iterator(), node1.NodeID)
assert.Assert(t, result == nil, "result should be nil since node1 is the reserved node")

// case 2: node is unschedulable
node2 := newNode(nodeID2, map[string]resources.Quantity{"first": 5})
node2.schedulable = false
iterator = getNodeIteratorFn(node2)
result = app.tryNodesNoReserve(ask, iterator(), node1.NodeID)
assert.Assert(t, result == nil, "result should be nil since node2 is unschedulable")

// case 3: node does not have enough resources
node3 := newNode("node-3", map[string]resources.Quantity{"first": 1})
chenyulin0719 marked this conversation as resolved.
Show resolved Hide resolved
iterator = getNodeIteratorFn(node3)
result = app.tryNodesNoReserve(ask, iterator(), node1.NodeID)
assert.Assert(t, result == nil, "result should be nil since node3 does not have enough resources")

// case 4: success
node4 := newNode("node-4", map[string]resources.Quantity{"first": 5})
iterator = getNodeIteratorFn(node4)
result = app.tryNodesNoReserve(ask, iterator(), node1.NodeID)
assert.Assert(t, result != nil, "result should not be nil")
assert.Equal(t, node4.NodeID, result.NodeID, "result should be on node4")
assert.Equal(t, result.ResultType, AllocatedReserved, "result type should be AllocatedReserved")
assert.Equal(t, result.ReservedNodeID, node1.NodeID, "reserved node should be node1")
}