Skip to content

Commit 45b323d

Browse files
committed
use Cleanup func
1 parent b1f6cfc commit 45b323d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/integration/scheduler_perf/scheduler_perf.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,6 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
15511551
executor.runSleepOp(concreteOp)
15521552
case *startCollectingMetricsOp:
15531553
executor.runStartCollectingMetricsOp(opIndex, concreteOp)
1554-
defer executor.collectorCtx.Cancel("cleaning up")
15551554
case *stopCollectingMetricsOp:
15561555
executor.runStopCollectingMetrics(opIndex)
15571556
default:
@@ -1661,7 +1660,11 @@ func (e *WorkloadExecutor) runCreatePodsOp(opIndex int, op *createPodsOp) {
16611660
e.tCtx.Fatalf("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one", opIndex)
16621661
}
16631662
e.collectorCtx, e.collectors = startCollectingMetrics(e.tCtx, &e.collectorWG, e.podInformer, e.testCase.MetricsCollectorConfig, e.throughputErrorMargin, opIndex, namespace, []string{namespace}, nil)
1664-
defer e.collectorCtx.Cancel("cleaning up")
1663+
e.tCtx.TB().Cleanup(func() {
1664+
if e.collectorCtx != nil {
1665+
e.collectorCtx.Cancel("cleaning up")
1666+
}
1667+
})
16651668
}
16661669
if err := createPodsRapidly(e.tCtx, namespace, op); err != nil {
16671670
e.tCtx.Fatalf("op %d: %v", opIndex, err)
@@ -1862,6 +1865,11 @@ func (e *WorkloadExecutor) runStartCollectingMetricsOp(opIndex int, op *startCol
18621865
e.tCtx.Fatalf("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one", opIndex)
18631866
}
18641867
e.collectorCtx, e.collectors = startCollectingMetrics(e.tCtx, &e.collectorWG, e.podInformer, e.testCase.MetricsCollectorConfig, e.throughputErrorMargin, opIndex, op.Name, op.Namespaces, op.LabelSelector)
1868+
e.tCtx.TB().Cleanup(func() {
1869+
if e.collectorCtx != nil {
1870+
e.collectorCtx.Cancel("cleaning up")
1871+
}
1872+
})
18651873
}
18661874

18671875
func createNamespaceIfNotPresent(tCtx ktesting.TContext, namespace string, podsPerNamespace *map[string]int) {

0 commit comments

Comments
 (0)