@@ -1224,18 +1224,28 @@ func TestMessageHandler_AlertMonitorError(t *testing.T) {
12241224 assert .Equal (t , models .DeliveryStatusSuccess , logPublisher .deliveries [0 ].Delivery .Status , "delivery status should be OK" )
12251225
12261226 // Verify alert monitor was called but error was ignored
1227+ // Wait for the HandleAttempt call to be made
1228+ require .Eventually (t , func () bool {
1229+ for _ , call := range alertMonitor .Calls {
1230+ if call .Method == "HandleAttempt" {
1231+ return true
1232+ }
1233+ }
1234+ return false
1235+ }, 200 * time .Millisecond , 10 * time .Millisecond , "timed out waiting for HandleAttempt call on alertMonitor" )
12271236 alertMonitor .AssertCalled (t , "HandleAttempt" , mock .Anything , mock .Anything )
12281237}
12291238
12301239// Helper function to assert alert monitor calls
12311240func assertAlertMonitor (t * testing.T , m * mockAlertMonitor , success bool , destination * models.Destination , expectedData map [string ]interface {}) {
12321241 t .Helper ()
12331242
1234- // Wait a bit for goroutines
1235- time .Sleep (100 * time .Millisecond )
1243+ // Wait for the alert monitor to be called
1244+ require .Eventually (t , func () bool {
1245+ return len (m .Calls ) > 0
1246+ }, 200 * time .Millisecond , 10 * time .Millisecond , "timed out waiting for alert monitor to be called" )
12361247
1237- calls := m .Calls
1238- require .NotEmpty (t , calls , "alert monitor should be called" )
1248+ calls := m .Calls // m.Calls is now guaranteed to be non-empty
12391249
12401250 lastCall := calls [len (calls )- 1 ]
12411251 attempt := lastCall .Arguments [1 ].(alert.DeliveryAttempt )
0 commit comments