@@ -184,8 +184,8 @@ func TestPostInstallApp(t *testing.T) {
184
184
rc .SetDataDir (t .TempDir ())
185
185
186
186
// Create mock metrics reporter - this is the key test for reporting handlers
187
- mockReporter := & metrics.MockReporter {}
188
- mockReporter .On ("ReportInstallationSucceeded" , mock .Anything )
187
+ mockMetricsReporter := & metrics.MockReporter {}
188
+ mockMetricsReporter .On ("ReportInstallationSucceeded" , mock .Anything )
189
189
190
190
// Create mock app install manager that succeeds
191
191
mockAppInstallManager := & appinstallmanager.MockAppInstallManager {}
@@ -220,7 +220,7 @@ func TestPostInstallApp(t *testing.T) {
220
220
installController , err := linuxinstall .NewInstallController (
221
221
linuxinstall .WithStateMachine (stateMachine ),
222
222
linuxinstall .WithAppInstallController (appInstallController ),
223
- linuxinstall .WithMetricsReporter (mockReporter ),
223
+ linuxinstall .WithMetricsReporter (mockMetricsReporter ),
224
224
linuxinstall .WithReleaseData (& release.ReleaseData {
225
225
EmbeddedClusterConfig : & ecv1beta1.Config {},
226
226
ChannelRelease : & release.ChannelRelease {
@@ -262,9 +262,13 @@ func TestPostInstallApp(t *testing.T) {
262
262
return stateMachine .CurrentState () == states .StateSucceeded
263
263
}, 10 * time .Second , 100 * time .Millisecond , "state should transition to Succeeded" )
264
264
265
- // Verify that ReportInstallationSucceeded was called
266
- mockReporter .AssertExpectations (t )
267
265
mockAppInstallManager .AssertExpectations (t )
266
+
267
+ // Wait for the event handler goroutine to complete
268
+ // TODO: find a better way to do this
269
+ time .Sleep (1 * time .Second )
270
+ // Verify that ReportInstallationSucceeded was called
271
+ mockMetricsReporter .AssertExpectations (t )
268
272
})
269
273
270
274
t .Run ("Invalid state transition" , func (t * testing.T ) {
@@ -319,8 +323,8 @@ func TestPostInstallApp(t *testing.T) {
319
323
rc .SetDataDir (t .TempDir ())
320
324
321
325
// Create mock metrics reporter expecting failure report
322
- mockReporter := & metrics.MockReporter {}
323
- mockReporter .On ("ReportInstallationFailed" , mock .Anything , mock .MatchedBy (func (err error ) bool {
326
+ mockMetricsReporter := & metrics.MockReporter {}
327
+ mockMetricsReporter .On ("ReportInstallationFailed" , mock .Anything , mock .MatchedBy (func (err error ) bool {
324
328
return err .Error () == "install app: installation failed"
325
329
}))
326
330
@@ -361,7 +365,7 @@ func TestPostInstallApp(t *testing.T) {
361
365
installController , err := linuxinstall .NewInstallController (
362
366
linuxinstall .WithStateMachine (stateMachine ),
363
367
linuxinstall .WithAppInstallController (appInstallController ),
364
- linuxinstall .WithMetricsReporter (mockReporter ),
368
+ linuxinstall .WithMetricsReporter (mockMetricsReporter ),
365
369
linuxinstall .WithStore (mockStore ),
366
370
linuxinstall .WithReleaseData (integration .DefaultReleaseData ()),
367
371
linuxinstall .WithRuntimeConfig (rc ),
@@ -395,10 +399,14 @@ func TestPostInstallApp(t *testing.T) {
395
399
return stateMachine .CurrentState () == states .StateAppInstallFailed
396
400
}, 10 * time .Second , 100 * time .Millisecond , "state should transition to AppInstallFailed" )
397
401
398
- // Verify that ReportInstallationFailed was called
399
- mockReporter .AssertExpectations (t )
400
402
mockAppInstallManager .AssertExpectations (t )
401
403
mockStore .AppInstallMockStore .AssertExpectations (t )
404
+
405
+ // Wait for the event handler goroutine to complete
406
+ // TODO: find a better way to do this
407
+ time .Sleep (1 * time .Second )
408
+ // Verify that ReportInstallationFailed was called
409
+ mockMetricsReporter .AssertExpectations (t )
402
410
})
403
411
404
412
t .Run ("Authorization error" , func (t * testing.T ) {
0 commit comments