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

ccondit 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 9d28ef27 [YUNIKORN-2732] Improve allocation & queue_events test 
coverage (#913)
9d28ef27 is described below

commit 9d28ef27c8554addd83907e22673984db9b4dfcd
Author: SP12893678 <[email protected]>
AuthorDate: Thu Jul 11 15:12:56 2024 -0500

    [YUNIKORN-2732] Improve allocation & queue_events test coverage (#913)
    
    Closes: #913
    
    Signed-off-by: Craig Condit <[email protected]>
---
 pkg/scheduler/objects/allocation_ask_test.go      | 14 ++++++++++++++
 pkg/scheduler/objects/allocation_test.go          |  7 +++++++
 pkg/scheduler/objects/events/queue_events_test.go | 13 +++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/pkg/scheduler/objects/allocation_ask_test.go 
b/pkg/scheduler/objects/allocation_ask_test.go
index ab8d722a..6a97b041 100644
--- a/pkg/scheduler/objects/allocation_ask_test.go
+++ b/pkg/scheduler/objects/allocation_ask_test.go
@@ -29,6 +29,7 @@ import (
        "github.com/apache/yunikorn-core/pkg/events/mock"
        schedEvt "github.com/apache/yunikorn-core/pkg/scheduler/objects/events"
        "github.com/apache/yunikorn-scheduler-interface/lib/go/common"
+       siCommon "github.com/apache/yunikorn-scheduler-interface/lib/go/common"
        "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
 )
 
@@ -226,6 +227,19 @@ func TestSendPredicateFailed(t *testing.T) {
        assert.Equal(t, "Predicate failed for request 'ask-1' with message: 
'failure'", event.Message)
 }
 
+func TestCreateTime(t *testing.T) {
+       siAsk := &si.AllocationAsk{
+               AllocationKey: "ask1",
+               ApplicationID: "app1",
+               PartitionName: "default",
+       }
+       siAsk.Tags = map[string]string{siCommon.CreationTime: "1622530800"}
+       ask := NewAllocationAskFromSI(siAsk)
+       assert.Equal(t, ask.GetTag(siCommon.CreationTime), "1622530800")
+       assert.Equal(t, ask.GetTag("unknown"), "")
+       assert.Equal(t, ask.GetCreateTime(), time.Unix(1622530800, 0))
+}
+
 func sortedLog(ask *AllocationAsk) []*AllocationLogEntry {
        log := ask.GetAllocationLog()
        sort.SliceStable(log, func(i int, j int) bool {
diff --git a/pkg/scheduler/objects/allocation_test.go 
b/pkg/scheduler/objects/allocation_test.go
index de4b70ad..2f2833dc 100644
--- a/pkg/scheduler/objects/allocation_test.go
+++ b/pkg/scheduler/objects/allocation_test.go
@@ -20,6 +20,7 @@ package objects
 
 import (
        "fmt"
+       "reflect"
        "strconv"
        "testing"
        "time"
@@ -71,6 +72,7 @@ func TestNewAlloc(t *testing.T) {
        ask.createTime = time.Unix(past, 0)
        alloc = NewAllocation("node-1", ask)
        assert.Equal(t, alloc.GetCreateTime(), ask.GetCreateTime(), "createTime 
was not copied from the ask")
+       assert.Assert(t, reflect.DeepEqual(ask.tags, ask.GetTagsClone()))
 }
 
 func TestNewAllocatedAllocationResult(t *testing.T) {
@@ -144,6 +146,10 @@ func TestAllocationResultString(t *testing.T) {
        // validate nil ask
        result.Ask = nil
        assert.Equal(t, result.String(), "resultType=Allocated, nodeID=node-1, 
reservedNodeID=node-2, allocationKey=", "wrong content")
+
+       // validate nil result
+       result = nil
+       assert.Equal(t, result.String(), "nil allocation result", "wrong 
content")
 }
 
 func TestSIFromNilAlloc(t *testing.T) {
@@ -243,6 +249,7 @@ func TestNewAllocFromSI(t *testing.T) {
        assert.Assert(t, alloc.IsOriginator(), "allocation should have been an 
originator")
        assert.Assert(t, !alloc.GetAsk().IsAllowPreemptSelf(), "ask should not 
have allow-preempt-self set")
        assert.Assert(t, alloc.GetAsk().IsAllowPreemptOther(), "ask should have 
allow-preempt-other set")
+       assert.Assert(t, reflect.DeepEqual(alloc.tags, alloc.GetTagsClone()))
 
        allocSI.Originator = false
        allocSI.PreemptionPolicy.AllowPreemptSelf = true
diff --git a/pkg/scheduler/objects/events/queue_events_test.go 
b/pkg/scheduler/objects/events/queue_events_test.go
index bae61d85..8e3e6069 100644
--- a/pkg/scheduler/objects/events/queue_events_test.go
+++ b/pkg/scheduler/objects/events/queue_events_test.go
@@ -141,6 +141,19 @@ func TestTypeChangedEvent(t *testing.T) {
        assert.Equal(t, si.EventRecord_SET, event.EventChangeType)
        assert.Equal(t, si.EventRecord_QUEUE_TYPE, event.EventChangeDetail)
        assert.Equal(t, 0, len(event.Resource.Resources))
+
+       eventSystem = mock.NewEventSystem()
+       nq = NewQueueEvents(eventSystem)
+       nq.SendTypeChangedEvent(testQueuePath, true)
+       assert.Equal(t, 1, len(eventSystem.Events), "event was not generated")
+       event = eventSystem.Events[0]
+       assert.Equal(t, si.EventRecord_QUEUE, event.Type)
+       assert.Equal(t, testQueuePath, event.ObjectID)
+       assert.Equal(t, common.Empty, event.ReferenceID)
+       assert.Equal(t, "leaf queue: true", event.Message)
+       assert.Equal(t, si.EventRecord_SET, event.EventChangeType)
+       assert.Equal(t, si.EventRecord_QUEUE_TYPE, event.EventChangeDetail)
+       assert.Equal(t, 0, len(event.Resource.Resources))
 }
 
 func TestSendMaxResourceChangedEvent(t *testing.T) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to