From 3aa9657c6bbba0c64e7cf3e35c781b2f2ef4edb4 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 19 Dec 2024 17:53:51 +0800 Subject: [PATCH] [YUNIKORN-2997] update and refactor based on reviews --- pkg/scheduler/objects/application_test.go | 34 ++++++++--------------- pkg/scheduler/objects/utilities_test.go | 3 ++ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/pkg/scheduler/objects/application_test.go b/pkg/scheduler/objects/application_test.go index 73941cd04..5a3206474 100644 --- a/pkg/scheduler/objects/application_test.go +++ b/pkg/scheduler/objects/application_test.go @@ -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") @@ -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 @@ -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()) @@ -1499,10 +1495,6 @@ func TestTimeoutPlaceholderHard(t *testing.T) { } func runTimeoutPlaceholderTest(t *testing.T, expectedState string, gangSchedulingStyle string) { - const ( - tg1 = "tg-1" - tg2 = "tg-2" - ) setupUGM() // create a fake queue @@ -1595,7 +1587,6 @@ func runTimeoutPlaceholderTest(t *testing.T, expectedState string, gangSchedulin } func TestTimeoutPlaceholderAllocReleased(t *testing.T) { - const tg1 = "tg-1" setupUGM() @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/pkg/scheduler/objects/utilities_test.go b/pkg/scheduler/objects/utilities_test.go index 20015a876..285aa5bb2 100644 --- a/pkg/scheduler/objects/utilities_test.go +++ b/pkg/scheduler/objects/utilities_test.go @@ -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" )