bgrams commented on code in PR #463:
URL: https://github.com/apache/yunikorn-core/pull/463#discussion_r1037805397


##########
pkg/scheduler/partition_test.go:
##########
@@ -1681,39 +1698,62 @@ func TestCompleteApp(t *testing.T) {
        assert.Assert(t, len(partition.applications) == 1, "the partition 
should have 1 app")
        assert.Assert(t, len(partition.completedApplications) == 0, "the 
partition should not have any completed apps")
        // complete the application
-       err = app.HandleApplicationEvent(objects.CompleteApplication)
-       assert.NilError(t, err, "no error expected while transitioning the app 
from waiting to completed state")
-       err = common.WaitFor(10*time.Millisecond, 
time.Duration(1000)*time.Millisecond, func() bool {
-               partition.RLock()
-               defer partition.RUnlock()
-               return len(partition.completedApplications) > 0
-       })
+       err = completeApplicationAndWait(app, partition)
        assert.NilError(t, err, "the completed application should have been 
processed")
        assert.Assert(t, len(partition.applications) == 0, "the partition 
should have no active app")
        assert.Assert(t, len(partition.completedApplications) == 1, "the 
partition should have 1 completed app")
 }
 
+func TestCleanupApp(t *testing.T) {
+       partition, err := newBasePartition()
+       assert.NilError(t, err, "partition create failed")
+       newApp1 := newApplication("newApp1", "default", defQueue)
+       newApp2 := newApplication("newApp2", "default", defQueue)
+
+       err = partition.AddApplication(newApp1)
+       assert.NilError(t, err, "no error expected while adding the app")
+       err = partition.AddApplication(newApp2)
+       assert.NilError(t, err, "no error expected while adding the app")
+
+       assert.Assert(t, len(partition.applications) == 2, "the partition 
should have 2 apps")
+
+       newApp1.SetState(objects.Expired.String())
+       partition.cleanupExpiredApps()
+
+       assert.Assert(t, len(partition.applications) == 1, "the partition 
should have 1 app")
+       assert.Assert(t, 
len(partition.GetAppsByState(objects.Expired.String())) == 0, "the partition 
should have 0 expired apps")
+}
+
 func TestCleanupCompletedApps(t *testing.T) {
        partition, err := newBasePartition()
        assert.NilError(t, err, "partition create failed")
-       completedApp := newApplication("completed", "default", defQueue)
-       completedApp.SetState(objects.Completed.String())
+       completedApp1 := newApplication("completedApp1", "default", defQueue)
+       completedApp2 := newApplication("completedApp2", "default", defQueue)
 
-       newApp := newApplication("running", "default", defQueue)
-       err = partition.AddApplication(completedApp)
-       assert.NilError(t, err, "no error expected while adding the 
application")
-       err = partition.AddApplication(newApp)
-       assert.NilError(t, err, "no error expected while adding the 
application")
+       err = partition.AddApplication(completedApp1)
+       assert.NilError(t, err, "no error expected while adding the app")
+       err = partition.AddApplication(completedApp2)
+       assert.NilError(t, err, "no error expected while adding the app")
 
        assert.Assert(t, len(partition.applications) == 2, "the partition 
should have 2 apps")
+       assert.Assert(t, len(partition.completedApplications) == 0, "the 
partition should have 0 completed apps")
+
+       // complete the applications using the event system
+       completedApp1.SetState(objects.Completing.String())
+       err = completeApplicationAndWait(completedApp1, partition)
+       assert.NilError(t, err, "the completed application should have been 
processed")
+       completedApp2.SetState(objects.Completing.String())
+       err = completeApplicationAndWait(completedApp2, partition)
+       assert.NilError(t, err, "the completed application should have been 
processed")
+
+       assert.Assert(t, len(partition.applications) == 0, "the partition 
should have 0 apps")
+       assert.Assert(t, len(partition.completedApplications) == 2, "the 
partition should have 2 completed apps")
+
        // mark the app for removal
-       completedApp.SetState(objects.Expired.String())
+       completedApp1.SetState(objects.Expired.String())
        partition.cleanupExpiredApps()
-       assert.Assert(t, len(partition.applications) == 1, "the partition 
should have 1 app")
-       assert.Assert(t, partition.getApplication(completedApp.ApplicationID) 
== nil, "completed application should have been deleted")
-       assert.Assert(t, partition.getApplication(newApp.ApplicationID) != nil, 
"new application should still be in the partition")
-       assert.Assert(t, 
len(partition.GetAppsByState(objects.Completed.String())) == 0, "the partition 
should have 0 completed app")
-       assert.Assert(t, 
len(partition.GetAppsByState(objects.Expired.String())) == 0, "the partition 
should have 0 expired app")

Review Comment:
   Noting that the removal of these is covered by the check in 
[L.1749](https://github.com/apache/yunikorn-core/pull/463/files#diff-2edfc3fe8b3fca0a3a2a8a3924a0c5a078e3f8e9046748067d65248b458aae6aR1749)
 as well as the refactor of 
[`TestCleanupApp`](https://github.com/apache/yunikorn-core/pull/463/files#diff-2edfc3fe8b3fca0a3a2a8a3924a0c5a078e3f8e9046748067d65248b458aae6aR1707)
 with a similar test structure. I'm open to feedback on this refactor.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to