Skip to content

Commit 274858d

Browse files
committed
errChan in test
1 parent 4b9668e commit 274858d

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

maintnotifications/e2e/scenario_push_notifications_test.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,16 @@ func TestPushNotifications(t *testing.T) {
248248
t.Fatalf("Failed to trigger bind action: %v", err)
249249
}
250250

251+
// Use a channel to communicate errors from the goroutine
252+
errChan := make(chan error, 1)
253+
251254
go func() {
255+
defer func() {
256+
if r := recover(); r != nil {
257+
errChan <- fmt.Errorf("goroutine panic: %v", r)
258+
}
259+
}()
260+
252261
p("Waiting for MOVING notification")
253262
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
254263
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING")
@@ -267,44 +276,53 @@ func TestPushNotifications(t *testing.T) {
267276
},
268277
})
269278
if err != nil {
270-
t.Fatalf("Failed to create client: %v", err)
279+
errChan <- fmt.Errorf("failed to create client: %v", err)
280+
return
271281
}
272282
tracker2 := NewTrackingNotificationsHook()
273283
logger2 := maintnotifications.NewLoggingHook(int(logging.LogLevelDebug))
274284
setupNotificationHooks(client2, tracker2, logger2)
275285
commandsRunner2, _ := NewCommandRunner(client2)
276286
go commandsRunner2.FireCommandsUntilStop(ctx)
287+
defer func() {
288+
// stop the second runner
289+
commandsRunner2.Stop()
290+
// destroy the second client
291+
factory.Destroy("push-notification-client-2")
292+
}()
277293
// wait for moving on second client
278294
// we know the maxconn is 15, so connID 17 should be from the second client
279295
// also validate big enough relaxed timeout
280296
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
281297
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING") && connID(s, 17)
282298
}, 2*time.Minute)
283299
if !found {
284-
t.Fatal("MOVING notification was not received within 2 minutes ON A SECOND CLIENT")
300+
errChan <- fmt.Errorf("MOVING notification was not received within 2 minutes ON A SECOND CLIENT")
301+
return
285302
}
286303
// wait for relaxation of 30m
287304
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
288305
return strings.Contains(s, logs2.ApplyingRelaxedTimeoutDueToPostHandoffMessage) && strings.Contains(s, "30m")
289306
}, 2*time.Minute)
290307
if !found {
291-
t.Fatal("Relaxed timeout was not applied within 2 minutes ON A SECOND CLIENT")
308+
errChan <- fmt.Errorf("relaxed timeout was not applied within 2 minutes ON A SECOND CLIENT")
309+
return
292310
}
293-
// stop the second runner
294-
commandsRunner2.Stop()
295-
// destroy the second client
296-
factory.Destroy("push-notification-client-2")
311+
// Signal success
312+
errChan <- nil
297313
}()
298314
commandsRunner.FireCommandsUntilStop(ctx)
299-
if !found {
300-
t.Fatal("MOVING notification was not received within 2 minutes ON A SECOND CLIENT")
301-
}
302315

303316
movingData := logs2.ExtractDataFromLogMessage(match)
304317
p("MOVING notification received. %v", movingData)
305318
seqIDToObserve = int64(movingData["seqID"].(float64))
306319
connIDToObserve = uint64(movingData["connID"].(float64))
307320

321+
// Wait for the goroutine to complete and check for errors
322+
if err := <-errChan; err != nil {
323+
t.Fatalf("Goroutine error: %v", err)
324+
}
325+
308326
// Wait for bind action to complete
309327
bindStatus, err := faultInjector.WaitForAction(ctx, bindResp.ActionID,
310328
WithMaxWaitTime(120*time.Second),

0 commit comments

Comments
 (0)