This is an automated email from the ASF dual-hosted git repository.

mani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 62271e57 [YUNIKORN-2176] Add test for user & group max resource 
changes (#726)
62271e57 is described below

commit 62271e57ff288134faa7c9a3e3860b6731df698f
Author: Manikandan R <maniraj...@gmail.com>
AuthorDate: Thu Dec 14 11:58:49 2023 +0530

    [YUNIKORN-2176] Add test for user & group max resource changes (#726)
    
    Closes: #726
    
    Signed-off-by: Manikandan R <maniraj...@gmail.com>
---
 pkg/scheduler/ugm/manager_test.go | 94 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/pkg/scheduler/ugm/manager_test.go 
b/pkg/scheduler/ugm/manager_test.go
index 2a2044ee..cfb6e6a9 100644
--- a/pkg/scheduler/ugm/manager_test.go
+++ b/pkg/scheduler/ugm/manager_test.go
@@ -45,10 +45,17 @@ var (
                "memory": "50",
                "vcores": "50",
        }
+       mediumResourceWithMemOnly = map[string]string{
+               "memory": "50",
+       }
+       mediumResourceWithVcoresOnly = map[string]string{
+               "vcores": "50",
+       }
        tinyResource = map[string]string{
                "memory": "25",
                "vcores": "25",
        }
+       nilResource = map[string]string{}
 )
 
 func TestUserManagerOnceInitialization(t *testing.T) {
@@ -1116,6 +1123,93 @@ func TestUserGroupLimit(t *testing.T) { //nolint:funlen
        }
 }
 
+func TestUserGroupMaxResourcesChange(t *testing.T) { //nolint:funlen
+       testCases := []struct {
+               name      string
+               user      security.UserGroup
+               limits    []configs.Limit
+               newLimits []configs.Limit
+       }{
+               {
+                       name: "Updated specific user & group max resources",
+                       user: security.UserGroup{User: "user1", Groups: 
[]string{"group1"}},
+                       limits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, largeResource, 2),
+                       },
+                       newLimits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, mediumResource, 2),
+                       },
+               },
+               {
+                       name: "Updated specific user & group max resources with 
mem only",
+                       user: security.UserGroup{User: "user1", Groups: 
[]string{"group1"}},
+                       limits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, mediumResource, 2),
+                       },
+                       newLimits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, mediumResourceWithMemOnly, 2),
+                       },
+               },
+               {
+                       name: "Updated specific user & group max resources with 
vcores only",
+                       user: security.UserGroup{User: "user1", Groups: 
[]string{"group1"}},
+                       limits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, mediumResourceWithMemOnly, 2),
+                       },
+                       newLimits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, mediumResourceWithVcoresOnly, 2),
+                       },
+               },
+               {
+                       name: "Updated specific user & group max resources with 
nil resource",
+                       user: security.UserGroup{User: "user1", Groups: 
[]string{"group1"}},
+                       limits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, mediumResourceWithMemOnly, 2),
+                       },
+                       newLimits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, nilResource, 2),
+                       },
+               },
+               {
+                       name: "Updated specific user & group max resources with 
nil",
+                       user: security.UserGroup{User: "user1", Groups: 
[]string{"group1"}},
+                       limits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, mediumResourceWithMemOnly, 2),
+                       },
+                       newLimits: []configs.Limit{
+                               createLimit([]string{"user1"}, 
[]string{"group1"}, nil, 2),
+                       },
+               },
+       }
+
+       for _, tc := range testCases {
+               t.Run(tc.name, func(t *testing.T) {
+                       setupUGM()
+
+                       manager := GetUserManager()
+                       conf := createConfigWithLimits(tc.limits)
+                       assert.NilError(t, manager.UpdateConfig(conf.Queues[0], 
"root"))
+
+                       expectedResource, err := 
resources.NewResourceFromConf(tc.limits[0].MaxResources)
+                       if err != nil {
+                               t.Errorf("new resource create returned error or 
wrong resource: error %t, res %v", err, expectedResource)
+                       }
+                       assert.Equal(t, 
resources.Equals(manager.GetUserTracker("user1").queueTracker.childQueueTrackers["parent"].maxResources,
 expectedResource), true)
+                       assert.Equal(t, 
resources.Equals(manager.GetGroupTracker("group1").queueTracker.childQueueTrackers["parent"].maxResources,
 expectedResource), true)
+
+                       conf.Queues[0].Queues[0].Limits = tc.newLimits
+                       assert.NilError(t, manager.UpdateConfig(conf.Queues[0], 
"root"))
+
+                       expectedResource, err = 
resources.NewResourceFromConf(tc.newLimits[0].MaxResources)
+                       if err != nil {
+                               t.Errorf("new resource create returned error or 
wrong resource: error %t, res %v", err, expectedResource)
+                       }
+                       assert.Equal(t, 
resources.Equals(manager.GetUserTracker("user1").queueTracker.childQueueTrackers["parent"].maxResources,
 expectedResource), true)
+                       assert.Equal(t, 
resources.Equals(manager.GetGroupTracker("group1").queueTracker.childQueueTrackers["parent"].maxResources,
 expectedResource), true)
+               })
+       }
+}
+
 func TestUserGroupLimitChange(t *testing.T) { //nolint:funlen
        testCases := []struct {
                name      string


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@yunikorn.apache.org
For additional commands, e-mail: issues-h...@yunikorn.apache.org

Reply via email to