@@ -16,7 +16,6 @@ import (
1616 "github.com/codeready-toolchain/toolchain-common/pkg/test/space"
1717 "github.com/codeready-toolchain/toolchain-common/pkg/test/usersignup"
1818
19- "github.com/stretchr/testify/assert"
2019 "github.com/stretchr/testify/require"
2120 runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
2221 logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -146,50 +145,20 @@ func TestInitializeCountersFromExistingResources(t *testing.T) {
146145 })
147146}
148147
149- func TestShouldNotInitializeAgain (t * testing.T ) {
150- // given
151- metrics .Reset ()
152- defer metrics .Reset ()
153-
154- initObjs := []runtimeclient.Object {}
155- for index := range 10 {
156- initObjs = append (initObjs , usersignup .NewUserSignup (usersignup .WithName (fmt .Sprintf ("user-%d" , index )), usersignup .WithAnnotation (toolchainv1alpha1 .UserSignupActivationCounterAnnotationKey , strconv .Itoa (index + 1 ))))
157- initObjs = append (initObjs , masteruserrecord .NewMasterUserRecord (t , fmt .Sprintf ("user-%d" , index ), masteruserrecord .TargetCluster ("member-1" )))
158- initObjs = append (initObjs , space .NewSpace (test .HostOperatorNs , fmt .Sprintf ("user-%d" , index ), space .WithSpecTargetCluster ("member-1" )))
159- }
160- fakeClient := test .NewFakeClient (t , initObjs ... )
161- err := metrics .Synchronize (context .TODO (), fakeClient , test .HostOperatorNs )
162- require .NoError (t , err )
163-
164- // when
165- err = fakeClient .Create (context .TODO (), masteruserrecord .NewMasterUserRecord (t , "ignored" , masteruserrecord .TargetCluster ("member-1" )))
166- require .NoError (t , err )
167- err = fakeClient .Create (context .TODO (), space .NewSpace (test .HostOperatorNs , "ignored" , space .WithSpecTargetCluster ("member-1" )))
168- require .NoError (t , err )
169- err = metrics .Synchronize (context .TODO (), fakeClient , test .HostOperatorNs )
170-
171- // then
172- require .NoError (t , err )
173- metricstest .AssertThatCountersAndMetrics (t ).
174- HaveMasterUserRecordsPerDomain (map [string ]int {
175- string (metrics .Internal ): 10 , // same value
176- }).
177- HaveSpacesForCluster ("member-1" , 10 )
178- }
179-
180148func TestMultipleExecutionsInParallel (t * testing.T ) {
181149 // given
182150 initObjs := []runtimeclient.Object {}
183151 for index := range 10 {
184- initObjs = append (initObjs , masteruserrecord .NewMasterUserRecord (t , fmt .Sprintf ("user-%d" , index ), masteruserrecord .TargetCluster ("member-1" )))
152+ initObjs = append (initObjs , usersignup .NewUserSignup (usersignup .WithName (fmt .Sprintf ("user-%d" , index )), usersignup .WithEmail (fmt .Sprintf ("user-%d@redhat.com" , index ))))
153+ initObjs = append (initObjs , masteruserrecord .NewMasterUserRecord (t , fmt .Sprintf ("user-%d" , index ), masteruserrecord .Email (fmt .Sprintf ("user-%d@redhat.com" , index )), masteruserrecord .TargetCluster ("member-1" )))
185154 initObjs = append (initObjs , space .NewSpace (test .HostOperatorNs , fmt .Sprintf ("user-%d" , index ), space .WithSpecTargetCluster ("member-1" )))
186155 }
187156 fakeClient := test .NewFakeClient (t , initObjs ... )
188157 metricstest .ResetCounters (t , fakeClient )
189158 latch := new (sync.WaitGroup )
190159 latch .Add (1 )
191160 waitForFinished := new (sync.WaitGroup )
192-
161+ // run 1002 iterations to increment and decrement counters in parallel
193162 for i := range 1002 {
194163 waitForFinished .Add (4 ) // 4 routines to increment counters
195164 if i < 1000 {
@@ -241,23 +210,11 @@ func TestMultipleExecutionsInParallel(t *testing.T) {
241210 }(i )
242211 }
243212
244- for range 102 {
245- waitForFinished .Add (1 )
246- go func () {
247- defer waitForFinished .Done ()
248- latch .Wait ()
249- err := metrics .Synchronize (context .TODO (), fakeClient , test .HostOperatorNs )
250- assert .NoError (t , err ) // require must only be used in the goroutine running the test function (testifylint)
251- }()
252- }
253-
254213 // when
255214 latch .Done ()
256215 waitForFinished .Wait ()
257- err := metrics .Synchronize (context .TODO (), fakeClient , test .HostOperatorNs )
258216
259217 // then
260- require .NoError (t , err )
261218 metricstest .AssertThatCountersAndMetrics (t ).
262219 HaveMasterUserRecordsPerDomain (map [string ]int {
263220 string (metrics .Internal ): 12 , // all MURs have `@redhat.com` email address
0 commit comments