Skip to content

Commit b1f6cfc

Browse files
committed
change defer order to pass test
1 parent fcce8aa commit b1f6cfc

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

test/integration/scheduler_perf/scheduler_perf.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,6 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
14961496

14971497
// Everything else started by this function gets stopped before it returns.
14981498
tCtx = ktesting.WithCancel(tCtx)
1499-
var wg sync.WaitGroup
1500-
defer wg.Wait()
1501-
defer tCtx.Cancel("workload is done")
15021499

15031500
var dataItems []DataItem
15041501

@@ -1507,14 +1504,12 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
15071504
// the metrics collecting needs to be sure that the goroutines
15081505
// are stopped.
15091506
var collectorCtx ktesting.TContext
1510-
var collectorWG sync.WaitGroup
1511-
defer collectorWG.Wait()
15121507

15131508
executor := WorkloadExecutor{
15141509
tCtx: tCtx,
1515-
wg: wg,
1510+
wg: sync.WaitGroup{},
15161511
collectorCtx: collectorCtx,
1517-
collectorWG: collectorWG,
1512+
collectorWG: sync.WaitGroup{},
15181513
collectors: collectors,
15191514
numPodsScheduledPerNamespace: make(map[string]int),
15201515
podInformer: podInformer,
@@ -1525,6 +1520,10 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
15251520
dataItems: dataItems,
15261521
}
15271522

1523+
defer executor.wg.Wait()
1524+
defer executor.collectorWG.Wait()
1525+
defer tCtx.Cancel("workload is done")
1526+
15281527
for opIndex, op := range unrollWorkloadTemplate(tCtx, tc.WorkloadTemplate, w) {
15291528
realOp, err := op.realOp.patchParams(w)
15301529
if err != nil {
@@ -1538,14 +1537,10 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
15381537
switch concreteOp := realOp.(type) {
15391538
case *createNodesOp:
15401539
executor.runCreateNodesOp(opIndex, concreteOp)
1541-
15421540
case *createNamespacesOp:
15431541
executor.runCreateNamespaceOp(opIndex, concreteOp)
15441542
case *createPodsOp:
15451543
executor.runCreatePodsOp(opIndex, concreteOp)
1546-
if executor.collectorCtx != nil {
1547-
executor.collectorCtx.Cancel("cleaning up")
1548-
}
15491544
case *deletePodsOp:
15501545
executor.runDeletePodsOp(opIndex, concreteOp)
15511546
case *churnOp:
@@ -1666,9 +1661,7 @@ func (e *WorkloadExecutor) runCreatePodsOp(opIndex int, op *createPodsOp) {
16661661
e.tCtx.Fatalf("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one", opIndex)
16671662
}
16681663
e.collectorCtx, e.collectors = startCollectingMetrics(e.tCtx, &e.collectorWG, e.podInformer, e.testCase.MetricsCollectorConfig, e.throughputErrorMargin, opIndex, namespace, []string{namespace}, nil)
1669-
// e.collectorCtx.Cleanup(func() {
1670-
// e.collectorCtx.Cancel("cleaning up")
1671-
// })
1664+
defer e.collectorCtx.Cancel("cleaning up")
16721665
}
16731666
if err := createPodsRapidly(e.tCtx, namespace, op); err != nil {
16741667
e.tCtx.Fatalf("op %d: %v", opIndex, err)
@@ -1869,9 +1862,6 @@ func (e *WorkloadExecutor) runStartCollectingMetricsOp(opIndex int, op *startCol
18691862
e.tCtx.Fatalf("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one", opIndex)
18701863
}
18711864
e.collectorCtx, e.collectors = startCollectingMetrics(e.tCtx, &e.collectorWG, e.podInformer, e.testCase.MetricsCollectorConfig, e.throughputErrorMargin, opIndex, op.Name, op.Namespaces, op.LabelSelector)
1872-
// e.collectorCtx.Cleanup(func() {
1873-
// collectorCtx.Cancel("cleaning up")
1874-
// })
18751865
}
18761866

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

0 commit comments

Comments
 (0)