Skip to content

Commit

Permalink
[YUNIKORN-2997] update and refactor based on reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael committed Dec 19, 2024
1 parent 4b58df8 commit 3aa9657
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
34 changes: 12 additions & 22 deletions pkg/scheduler/objects/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,6 @@ func TestAddAllocAsk(t *testing.T) {
assert.Assert(t, app.IsAccepted(), "Application should have stayed in accepted state")

// test PlaceholderData
const (
tg1 = "tg-1"
tg2 = "tg-2"
)
ask = newAllocationAskTG(aKey, appID1, tg1, res)
err = app.AddAllocationAsk(ask)
assert.NilError(t, err, "ask should have been updated on app")
Expand Down Expand Up @@ -859,7 +855,7 @@ func TestStateChangeOnPlaceholderAdd(t *testing.T) {
assert.Assert(t, app.IsNew(), "New application did not return new state: %s", app.CurrentState())
res := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 1})
askID := "ask-1"
ask := newAllocationAskTG(askID, appID1, "TG1", res)
ask := newAllocationAskTG(askID, appID1, tg1, res)
err = app.AddAllocationAsk(ask)
assert.NilError(t, err, "ask should have been added to app")
// app with ask, even for placeholder, should be accepted
Expand All @@ -884,7 +880,7 @@ func TestStateChangeOnPlaceholderAdd(t *testing.T) {
// app with ask should be accepted
assert.Assert(t, app.IsAccepted(), "Application did not change to accepted state: %s", app.CurrentState())
// add an alloc based on the placeholder ask
allocInfo := newAllocationAll(askID, appID1, nodeID1, "TG1", res, true, 0)
allocInfo := newAllocationAll(askID, appID1, nodeID1, tg1, res, true, 0)
app.AddAllocation(allocInfo)
// app should be in the same state as it was before as it is a placeholder allocation
assert.Assert(t, app.IsAccepted(), "Application did not return accepted state after alloc: %s", app.CurrentState())
Expand Down Expand Up @@ -1499,10 +1495,6 @@ func TestTimeoutPlaceholderHard(t *testing.T) {
}

func runTimeoutPlaceholderTest(t *testing.T, expectedState string, gangSchedulingStyle string) {

Check failure on line 1497 in pkg/scheduler/objects/application_test.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)
const (
tg1 = "tg-1"
tg2 = "tg-2"
)

setupUGM()
// create a fake queue
Expand Down Expand Up @@ -1595,7 +1587,6 @@ func runTimeoutPlaceholderTest(t *testing.T, expectedState string, gangSchedulin
}

func TestTimeoutPlaceholderAllocReleased(t *testing.T) {

Check failure on line 1589 in pkg/scheduler/objects/application_test.go

View workflow job for this annotation

GitHub Actions / build

unnecessary leading newline (whitespace)
const tg1 = "tg-1"

setupUGM()

Expand Down Expand Up @@ -3440,8 +3431,6 @@ func TestApplication_canAllocationReserve(t *testing.T) {
}

func TestTryPlaceHolderAllocateNoPlaceHolders(t *testing.T) {
const tg1 = "tg-1"

node := newNode(nodeID1, map[string]resources.Quantity{"first": 5})
nodeMap := map[string]*Node{nodeID1: node}
iterator := getNodeIteratorFn(node)
Expand All @@ -3466,8 +3455,6 @@ func TestTryPlaceHolderAllocateNoPlaceHolders(t *testing.T) {
}

func TestTryPlaceHolderAllocateSmallerRequest(t *testing.T) {
const tg1 = "tg-1"

node := newNode(nodeID1, map[string]resources.Quantity{"first": 5})
nodeMap := map[string]*Node{nodeID1: node}
iterator := getNodeIteratorFn(node)
Expand Down Expand Up @@ -3496,11 +3483,16 @@ func TestTryPlaceHolderAllocateSmallerRequest(t *testing.T) {

result := app.tryPlaceholderAllocate(iterator, getNode)
assert.Assert(t, result != nil, "result should not be nil since the ask is smaller than the placeholder")
assert.Equal(t, Replaced, result.ResultType, "result type should be Replaced")
assert.Equal(t, nodeID1, result.NodeID, "result should be on the same node as placeholder")
assert.Equal(t, ask, result.Request, "result should contain the ask")
assert.Equal(t, ph, result.Request.GetRelease(), "real allocation should link to placeholder")
assert.Equal(t, result.Request, ph.GetRelease(), "placeholder should link to real allocation")
// placeholder data remains unchanged until RM confirms the replacement
assertPlaceholderData(t, app, tg1, 1, 0, 0, res)
}

func TestTryPlaceHolderAllocateLargerRequest(t *testing.T) {
const tg1 = "tg-1"

node := newNode(nodeID1, map[string]resources.Quantity{"first": 5})
nodeMap := map[string]*Node{nodeID1: node}
iterator := getNodeIteratorFn(node)
Expand Down Expand Up @@ -3529,14 +3521,12 @@ func TestTryPlaceHolderAllocateLargerRequest(t *testing.T) {

result := app.tryPlaceholderAllocate(iterator, getNode)
assert.Assert(t, result == nil, "result should be nil since the ask is larger than the placeholder")
assert.Assert(t, ph.IsReleased(), "placeholder should have been released")
// placeholder data remains unchanged until RM confirms the release
assertPlaceholderData(t, app, tg1, 1, 0, 0, res)
}

func TestTryPlaceHolderAllocateDifferentTaskGroups(t *testing.T) {
const (
tg1 = "tg-1"
tg2 = "tg-2"
)

node := newNode(nodeID1, map[string]resources.Quantity{"first": 5})
nodeMap := map[string]*Node{nodeID1: node}
iterator := getNodeIteratorFn(node)
Expand Down
3 changes: 3 additions & 0 deletions pkg/scheduler/objects/utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const (
nodeID2 = "node-2"
instType1 = "itype-1"
testgroup = "testgroup"
tg1 = "tg-1"
tg2 = "tg-2"
tg3 = "tg-3"
foreignAlloc1 = "foreign-1"
foreignAlloc2 = "foreign-2"
)
Expand Down

0 comments on commit 3aa9657

Please sign in to comment.