@@ -1551,7 +1551,6 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1551
1551
executor .runSleepOp (concreteOp )
1552
1552
case * startCollectingMetricsOp :
1553
1553
executor .runStartCollectingMetricsOp (opIndex , concreteOp )
1554
- defer executor .collectorCtx .Cancel ("cleaning up" )
1555
1554
case * stopCollectingMetricsOp :
1556
1555
executor .runStopCollectingMetrics (opIndex )
1557
1556
default :
@@ -1661,7 +1660,11 @@ func (e *WorkloadExecutor) runCreatePodsOp(opIndex int, op *createPodsOp) {
1661
1660
e .tCtx .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1662
1661
}
1663
1662
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
+ })
1665
1668
}
1666
1669
if err := createPodsRapidly (e .tCtx , namespace , op ); err != nil {
1667
1670
e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
@@ -1862,6 +1865,11 @@ func (e *WorkloadExecutor) runStartCollectingMetricsOp(opIndex int, op *startCol
1862
1865
e .tCtx .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1863
1866
}
1864
1867
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
+ })
1865
1873
}
1866
1874
1867
1875
func createNamespaceIfNotPresent (tCtx ktesting.TContext , namespace string , podsPerNamespace * map [string ]int ) {
0 commit comments