@@ -1496,9 +1496,6 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1496
1496
1497
1497
// Everything else started by this function gets stopped before it returns.
1498
1498
tCtx = ktesting .WithCancel (tCtx )
1499
- var wg sync.WaitGroup
1500
- defer wg .Wait ()
1501
- defer tCtx .Cancel ("workload is done" )
1502
1499
1503
1500
var dataItems []DataItem
1504
1501
@@ -1507,14 +1504,12 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1507
1504
// the metrics collecting needs to be sure that the goroutines
1508
1505
// are stopped.
1509
1506
var collectorCtx ktesting.TContext
1510
- var collectorWG sync.WaitGroup
1511
- defer collectorWG .Wait ()
1512
1507
1513
1508
executor := WorkloadExecutor {
1514
1509
tCtx : tCtx ,
1515
- wg : wg ,
1510
+ wg : sync. WaitGroup {} ,
1516
1511
collectorCtx : collectorCtx ,
1517
- collectorWG : collectorWG ,
1512
+ collectorWG : sync. WaitGroup {} ,
1518
1513
collectors : collectors ,
1519
1514
numPodsScheduledPerNamespace : make (map [string ]int ),
1520
1515
podInformer : podInformer ,
@@ -1525,6 +1520,10 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1525
1520
dataItems : dataItems ,
1526
1521
}
1527
1522
1523
+ defer executor .wg .Wait ()
1524
+ defer executor .collectorWG .Wait ()
1525
+ defer tCtx .Cancel ("workload is done" )
1526
+
1528
1527
for opIndex , op := range unrollWorkloadTemplate (tCtx , tc .WorkloadTemplate , w ) {
1529
1528
realOp , err := op .realOp .patchParams (w )
1530
1529
if err != nil {
@@ -1538,14 +1537,10 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
1538
1537
switch concreteOp := realOp .(type ) {
1539
1538
case * createNodesOp :
1540
1539
executor .runCreateNodesOp (opIndex , concreteOp )
1541
-
1542
1540
case * createNamespacesOp :
1543
1541
executor .runCreateNamespaceOp (opIndex , concreteOp )
1544
1542
case * createPodsOp :
1545
1543
executor .runCreatePodsOp (opIndex , concreteOp )
1546
- if executor .collectorCtx != nil {
1547
- executor .collectorCtx .Cancel ("cleaning up" )
1548
- }
1549
1544
case * deletePodsOp :
1550
1545
executor .runDeletePodsOp (opIndex , concreteOp )
1551
1546
case * churnOp :
@@ -1666,9 +1661,7 @@ func (e *WorkloadExecutor) runCreatePodsOp(opIndex int, op *createPodsOp) {
1666
1661
e .tCtx .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1667
1662
}
1668
1663
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" )
1672
1665
}
1673
1666
if err := createPodsRapidly (e .tCtx , namespace , op ); err != nil {
1674
1667
e .tCtx .Fatalf ("op %d: %v" , opIndex , err )
@@ -1869,9 +1862,6 @@ func (e *WorkloadExecutor) runStartCollectingMetricsOp(opIndex int, op *startCol
1869
1862
e .tCtx .Fatalf ("op %d: Metrics collection is overlapping. Probably second collector was started before stopping a previous one" , opIndex )
1870
1863
}
1871
1864
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
- // })
1875
1865
}
1876
1866
1877
1867
func createNamespaceIfNotPresent (tCtx ktesting.TContext , namespace string , podsPerNamespace * map [string ]int ) {
0 commit comments