6565 // Some architectures don't have local ssd. Give way to opt out of tests like datacache.
6666 skipLocalSsdTests = flag .Bool ("skip-local-ssd-tests" , false , "Skip local ssd tests like datacache" )
6767
68- testContexts = []* remote.TestContext {}
69- hyperdiskTestContexts = []* remote.TestContext {}
68+ testContexts []* remote.TestContext
69+ hyperdiskTestContexts []* remote.TestContext
7070 computeService * compute.Service
7171 computeAlphaService * computealpha.Service
7272 computeBetaService * computebeta.Service
@@ -87,10 +87,6 @@ var _ = BeforeSuite(func() {
8787 var err error
8888 numberOfInstancesPerZone := 2
8989 zones := strings .Split (* zones , "," )
90- tcc := make (chan * remote.TestContext , len (zones )* numberOfInstancesPerZone )
91- hdtcc := make (chan * remote.TestContext , len (zones ))
92- defer close (tcc )
93- defer close (hdtcc )
9490
9591 rand .Seed (time .Now ().UnixNano ())
9692
@@ -116,42 +112,40 @@ var _ = BeforeSuite(func() {
116112
117113 klog .Infof ("Running in project %v with service account %v" , * project , * serviceAccount )
118114
119- setupContext := func (zone string ) {
120- var wg sync.WaitGroup
115+ testContexts = make ([]* remote.TestContext , numberOfInstancesPerZone * len (zones ))
116+ if * hdMachineType != noMachineType {
117+ hyperdiskTestContexts = make ([]* remote.TestContext , len (zones ))
118+ }
119+ var wg sync.WaitGroup
120+ setupContext := func (idx int , zone string ) {
121121 // Create 2 instances for each zone as we need 2 instances each zone for certain test cases
122122 for j := 0 ; j < numberOfInstancesPerZone ; j ++ {
123123 wg .Add (1 )
124124 go func (curZone string , randInt int ) {
125125 defer GinkgoRecover ()
126126 defer wg .Done ()
127- tcc <- NewDefaultTestContext (curZone , strconv .Itoa (randInt ))
127+ tc := NewDefaultTestContext (curZone , strconv .Itoa (randInt ))
128+ k := j + idx * numberOfInstancesPerZone
129+ testContexts [k ] = tc
130+ klog .Infof ("Added TestContext for node %s at %d" , tc .Instance .GetName (), k )
128131 }(zone , j )
129132 }
130- if * hdMachineType != noMachineType {
133+ if hyperdiskTestContexts != nil {
131134 wg .Add (1 )
132135 go func (curZone string ) {
133136 defer GinkgoRecover ()
134137 defer wg .Done ()
135- hdtcc <- NewTestContext (curZone , * hdMinCpuPlatform , * hdMachineType , "0" )
138+ tc := NewTestContext (curZone , * hdMinCpuPlatform , * hdMachineType , "0" )
139+ hyperdiskTestContexts [idx ] = tc
140+ klog .Infof ("Added hyperdisk TestContext for node %s at %d" , tc .Instance .GetName (), idx )
136141 }(zone )
137142 }
138- wg .Wait ()
139- }
140-
141- for _ , zone := range zones {
142- setupContext (zone )
143143 }
144144
145- for i := 0 ; i < len (zones )* numberOfInstancesPerZone ; i ++ {
146- tc := <- tcc
147- testContexts = append (testContexts , tc )
148- klog .Infof ("Added TestContext for node %s" , tc .Instance .GetName ())
149- }
150- for i := 0 ; i < len (zones ); i ++ {
151- tc := <- hdtcc
152- hyperdiskTestContexts = append (hyperdiskTestContexts , tc )
153- klog .Infof ("Added TestContext for node %s" , tc .Instance .GetName ())
145+ for i , zone := range zones {
146+ setupContext (i , zone )
154147 }
148+ wg .Wait ()
155149})
156150
157151var _ = AfterSuite (func () {
0 commit comments