Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuqi-lucas committed Sep 13, 2024
1 parent 9d9ef42 commit f1883b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 11 additions & 0 deletions pkg/scheduler/objects/application_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func TestAppStateTransitionMetrics(t *testing.T) { //nolint:funlen
// app-00001: New -> Resuming -> Accepted --> Running -> Completing-> Completed
app := newApplication("app-00001", "default", "root.metrics")
app.SetQueue(queue)
app.SetNewMetrics()
assertState(t, app, nil, New.String())
assertTotalAppsNewMetrics(t, 1)
assertTotalAppsRunningMetrics(t, 0)
Expand Down Expand Up @@ -398,6 +399,7 @@ func TestAppStateTransitionMetrics(t *testing.T) { //nolint:funlen
// app-00002: New -> Accepted -> Completing -> Running -> Failing-> Failed
app = newApplication("app-00002", "default", "root.metrics")
app.SetQueue(queue)
app.SetNewMetrics()
assertState(t, app, nil, New.String())
// New -> Accepted
err = app.HandleApplicationEvent(RunApplication)
Expand Down Expand Up @@ -432,6 +434,7 @@ func TestAppStateTransitionMetrics(t *testing.T) { //nolint:funlen
// app-00003: New -> Accepted -> Running -> Failing -> Failed
app = newApplication("app-00003", "default", "root.metrics")
app.SetQueue(queue)
app.SetNewMetrics()
assertState(t, app, nil, New.String())
// New -> Accepted
err = app.HandleApplicationEvent(RunApplication)
Expand Down Expand Up @@ -460,6 +463,7 @@ func TestAppStateTransitionMetrics(t *testing.T) { //nolint:funlen
// app-00004: New -> Rejected
app = newApplication("app-00004", "default", "root.metrics")
app.SetQueue(queue)
app.SetNewMetrics()
assertState(t, app, nil, New.String())
// New -> Rejected
err = app.HandleApplicationEvent(RejectApplication)
Expand All @@ -476,6 +480,13 @@ func TestAppStateTransitionMetrics(t *testing.T) { //nolint:funlen
assertQueueApplicationsRejectedMetrics(t, app, 1)
assertQueueApplicationsFailedMetrics(t, app, 2)
assertQueueApplicationsCompletedMetrics(t, app, 1)

// app-00005: the queuePath is empty, it will happen for dynamic queue when it before the queue is created
app = newApplication("app-00005", "default", "")
app.SetNewMetrics()
assertState(t, app, nil, New.String())
assertQueueApplicationsNewMetrics(t, app, 0)
assertTotalAppsNewMetrics(t, 4)
}

func assertState(t testing.TB, app *Application, err error, expected string) {
Expand Down
4 changes: 0 additions & 4 deletions pkg/scheduler/objects/utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/apache/yunikorn-core/pkg/common/resources"
"github.com/apache/yunikorn-core/pkg/common/security"
"github.com/apache/yunikorn-core/pkg/events"
"github.com/apache/yunikorn-core/pkg/metrics"
"github.com/apache/yunikorn-core/pkg/rmproxy"
schedEvt "github.com/apache/yunikorn-core/pkg/scheduler/objects/events"
"github.com/apache/yunikorn-core/pkg/scheduler/ugm"
Expand Down Expand Up @@ -116,9 +115,6 @@ func createDynamicQueue(parentSQ *Queue, name string, parent bool) (*Queue, erro
// Create application with minimal info
func newApplication(appID, partition, queueName string) *Application {
tags := make(map[string]string)
// Add for testing, because we now set the new metrics after we can define the queue
metrics.GetQueueMetrics(queueName).IncQueueApplicationsNew()
metrics.GetSchedulerMetrics().IncTotalApplicationsNew()
return newApplicationWithTags(appID, partition, queueName, tags)
}

Expand Down

0 comments on commit f1883b6

Please sign in to comment.