@@ -26,6 +26,7 @@ import (
26
26
"strconv"
27
27
"strings"
28
28
"sync"
29
+ "sync/atomic"
29
30
"testing"
30
31
"time"
31
32
@@ -132,6 +133,7 @@ csistoragecapacities_obsolete %d
132
133
// TestCapacityController checks that the controller handles the initial state and
133
134
// several different changes at runtime correctly.
134
135
func TestCapacityController (t * testing.T ) {
136
+ utilruntime .ReallyCrash = false // avoids os.Exit after "close of closed channel" in shared informer code
135
137
testcases := map [string ]struct {
136
138
immediateBinding bool
137
139
owner * metav1.OwnerReference
@@ -1339,10 +1341,6 @@ func updateCSIStorageCapacityReactor() func(action ktesting.Action) (handled boo
1339
1341
}
1340
1342
1341
1343
func fakeController (ctx context.Context , client * fakeclientset.Clientset , owner * metav1.OwnerReference , storage CSICapacityClient , topologyInformer topology.Informer , immediateBinding bool ) (* Controller , metrics.KubeRegistry ) {
1342
- utilruntime .ReallyCrash = false // avoids os.Exit after "close of closed channel" in shared informer code
1343
-
1344
- // We don't need resyncs, they just lead to confusing log output if they get triggered while already some
1345
- // new test is running.
1346
1344
resyncPeriod := time .Hour
1347
1345
informerFactory := informers .NewSharedInformerFactory (client , resyncPeriod )
1348
1346
scInformer := informerFactory .Storage ().V1 ().StorageClasses ()
@@ -1608,10 +1606,10 @@ func str2quantity(str string) *resource.Quantity {
1608
1606
return & quantity
1609
1607
}
1610
1608
1611
- var capacityCounter int
1609
+ var capacityCounter atomic. Int32
1612
1610
1613
1611
func makeCapacity (in testCapacity ) * storagev1.CSIStorageCapacity {
1614
- capacityCounter ++
1612
+ capacityCounter . Add ( 1 )
1615
1613
var owners []metav1.OwnerReference
1616
1614
switch in .owner {
1617
1615
case nil :
@@ -1638,7 +1636,7 @@ func makeCapacity(in testCapacity) *storagev1.CSIStorageCapacity {
1638
1636
ObjectMeta : metav1.ObjectMeta {
1639
1637
UID : in .uid ,
1640
1638
ResourceVersion : in .resourceVersion ,
1641
- Name : fmt .Sprintf ("csisc-%d" , capacityCounter ),
1639
+ Name : fmt .Sprintf ("csisc-%d" , capacityCounter . Load () ),
1642
1640
Namespace : ownerNamespace ,
1643
1641
OwnerReferences : owners ,
1644
1642
Labels : labels ,
0 commit comments