Skip to content

Commit 0c9a3f8

Browse files
mitdesaiclaude
andcommitted
Add tests for TryNodeCount/TryApplicationCount metrics and fix coverage gaps
- Add TestTryNodeCount covering AddTryNodeCount, GetTryNodeCount, ResetTryNodeCount - Add TestTryApplicationCount covering AddTryApplicationCount, ResetTryApplicationCount - Fix unregisterMetrics to also unregister tryApplicationCount - Add ApplicationsTried assertion to TestApplicationsTriedCount - Fix stale comments in TestApplicationsTriedCount Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bc3ba83 commit 0c9a3f8

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

pkg/metrics/scheduler_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,44 @@ func verifyMetric(t *testing.T, expectedCounter float64, expectedState string, n
232232
assert.Assert(t, checked, "Failed to find metric")
233233
}
234234

235+
func TestTryNodeCount(t *testing.T) {
236+
sm = getSchedulerMetrics(t)
237+
defer unregisterMetrics()
238+
239+
sm.AddTryNodeCount(5)
240+
count, err := sm.GetTryNodeCount()
241+
assert.NilError(t, err)
242+
assert.Equal(t, int64(5), count)
243+
244+
sm.AddTryNodeCount(3)
245+
count, err = sm.GetTryNodeCount()
246+
assert.NilError(t, err)
247+
assert.Equal(t, int64(8), count)
248+
249+
sm.ResetTryNodeCount()
250+
sm.AddTryNodeCount(1)
251+
count, err = sm.GetTryNodeCount()
252+
assert.NilError(t, err)
253+
assert.Equal(t, int64(1), count)
254+
}
255+
256+
func TestTryApplicationCount(t *testing.T) {
257+
sm = getSchedulerMetrics(t)
258+
defer unregisterMetrics()
259+
260+
sm.AddTryApplicationCount(4)
261+
metricDto := &dto.Metric{}
262+
err := sm.tryApplicationCount.With(nil).Write(metricDto)
263+
assert.NilError(t, err)
264+
assert.Equal(t, int64(4), int64(*metricDto.Counter.Value))
265+
266+
sm.ResetTryApplicationCount()
267+
sm.AddTryApplicationCount(2)
268+
err = sm.tryApplicationCount.With(nil).Write(metricDto)
269+
assert.NilError(t, err)
270+
assert.Equal(t, int64(2), int64(*metricDto.Counter.Value))
271+
}
272+
235273
func unregisterMetrics() {
236274
sm := GetSchedulerMetrics()
237275
prometheus.Unregister(sm.containerAllocation)
@@ -245,4 +283,5 @@ func unregisterMetrics() {
245283
prometheus.Unregister(sm.tryNodeEvaluation)
246284
prometheus.Unregister(sm.tryPreemptionLatency)
247285
prometheus.Unregister(sm.tryNodeCount)
286+
prometheus.Unregister(sm.tryApplicationCount)
248287
}

pkg/scheduler/objects/application_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,7 @@ func TestTryAllocateWithReservedHeadRoomChecking(t *testing.T) {
33293329

33303330
// pass the time and try again
33313331
reservationWaitTimeout = -60 * time.Second
3332-
result = app.tryReservedAllocate(headRoom, iter)
3332+
result, _ = app.tryReservedAllocate(headRoom, iter)
33333333
assert.Assert(t, result == nil, "result is expected to be nil due to insufficient headroom")
33343334
assert.Equal(t, len(app.reservations), 0)
33353335

pkg/scheduler/partition_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,8 +1664,9 @@ func TestApplicationsTriedCount(t *testing.T) {
16641664
t.Fatal("allocation did not return any allocation")
16651665
}
16661666
assert.Equal(t, result.ResultType, objects.Allocated, "result type is not the expected allocated")
1667-
assert.Equal(t, result.Request.GetApplicationID(), appID3, "expected application app-2 to be allocated")
1668-
assert.Equal(t, result.Request.GetAllocationKey(), allocKey3, "expected ask alloc-2 to be allocated")
1667+
assert.Equal(t, result.Request.GetApplicationID(), appID3, "expected application app-3 to be allocated")
1668+
assert.Equal(t, result.Request.GetAllocationKey(), allocKey3, "expected ask alloc-3 to be allocated")
1669+
assert.Equal(t, result.ApplicationsTried, int64(3), "expected 3 applications to be tried")
16691670
}
16701671

16711672
func TestNodesTriedCount(t *testing.T) {

0 commit comments

Comments
 (0)