Skip to content

Commit e33c72e

Browse files
committed
test with second client after action has started
1 parent 0bdee99 commit e33c72e

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

maintnotifications/e2e/scenario_push_notifications_test.go

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func TestPushNotifications(t *testing.T) {
3838
t.Logf(format, args...)
3939
}
4040

41+
var errorsDetected = false
4142
var e = func(format string, args ...interface{}) {
43+
errorsDetected = true
4244
format = "[%s][ERROR] " + format
4345
ts := time.Now().Format("15:04:05.000")
4446
args = append([]interface{}{ts}, args...)
@@ -248,6 +250,28 @@ func TestPushNotifications(t *testing.T) {
248250
t.Fatalf("Failed to trigger bind action: %v", err)
249251
}
250252

253+
// start a second client but don't execute any commands on it
254+
p("Starting a second client to observe notification during moving...")
255+
client2, err := factory.Create("push-notification-client-2", &CreateClientOptions{
256+
Protocol: 3, // RESP3 required for push notifications
257+
PoolSize: poolSize,
258+
MinIdleConns: minIdleConns,
259+
MaxActiveConns: maxConnections,
260+
MaintNotificationsConfig: &maintnotifications.Config{
261+
Mode: maintnotifications.ModeEnabled,
262+
RelaxedTimeout: 30 * time.Minute,
263+
},
264+
})
265+
if err != nil {
266+
t.Fatalf("failed to create client: %v", err)
267+
}
268+
// setup tracking for second client
269+
tracker2 := NewTrackingNotificationsHook()
270+
logger2 := maintnotifications.NewLoggingHook(int(logging.LogLevelDebug))
271+
setupNotificationHooks(client2, tracker2, logger2)
272+
commandsRunner2, _ := NewCommandRunner(client2)
273+
t.Log("Second client created")
274+
251275
// Use a channel to communicate errors from the goroutine
252276
errChan := make(chan error, 1)
253277

@@ -263,26 +287,8 @@ func TestPushNotifications(t *testing.T) {
263287
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING")
264288
}, 2*time.Minute)
265289
commandsRunner.Stop()
266-
267-
p("Starting a second client to observe notification during moving...")
268-
client2, err := factory.Create("push-notification-client-2", &CreateClientOptions{
269-
Protocol: 3, // RESP3 required for push notifications
270-
PoolSize: poolSize,
271-
MinIdleConns: minIdleConns,
272-
MaxActiveConns: maxConnections,
273-
MaintNotificationsConfig: &maintnotifications.Config{
274-
Mode: maintnotifications.ModeEnabled,
275-
RelaxedTimeout: 30 * time.Minute,
276-
},
277-
})
278-
if err != nil {
279-
errChan <- fmt.Errorf("failed to create client: %v", err)
280-
return
281-
}
282-
tracker2 := NewTrackingNotificationsHook()
283-
logger2 := maintnotifications.NewLoggingHook(int(logging.LogLevelDebug))
284-
setupNotificationHooks(client2, tracker2, logger2)
285-
commandsRunner2, _ := NewCommandRunner(client2)
290+
// once moving is received, start a second client commands runner
291+
p("Starting commands on second client")
286292
go commandsRunner2.FireCommandsUntilStop(ctx)
287293
defer func() {
288294
// stop the second runner
@@ -291,14 +297,16 @@ func TestPushNotifications(t *testing.T) {
291297
factory.Destroy("push-notification-client-2")
292298
}()
293299
// wait for moving on second client
294-
// we know the maxconn is 15, so connID 17 should be from the second client
300+
// we know the maxconn is 15, assuming 16/17 was used to init the second client, so connID 18 should be from the second client
295301
// also validate big enough relaxed timeout
296302
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
297-
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING") && connID(s, 17)
303+
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING") && connID(s, 18)
298304
}, 2*time.Minute)
299305
if !found {
300306
errChan <- fmt.Errorf("MOVING notification was not received within 2 minutes ON A SECOND CLIENT")
301307
return
308+
} else {
309+
p("MOVING notification received on second client %v", logs2.ExtractDataFromLogMessage(match))
302310
}
303311
// wait for relaxation of 30m
304312
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
@@ -307,6 +315,8 @@ func TestPushNotifications(t *testing.T) {
307315
if !found {
308316
errChan <- fmt.Errorf("relaxed timeout was not applied within 2 minutes ON A SECOND CLIENT")
309317
return
318+
} else {
319+
p("Relaxed timeout applied on second client")
310320
}
311321
// Signal success
312322
errChan <- nil
@@ -320,7 +330,7 @@ func TestPushNotifications(t *testing.T) {
320330

321331
// Wait for the goroutine to complete and check for errors
322332
if err := <-errChan; err != nil {
323-
t.Fatalf("Goroutine error: %v", err)
333+
t.Fatalf("Second client goroutine error: %v", err)
324334
}
325335

326336
// Wait for bind action to complete
@@ -335,9 +345,9 @@ func TestPushNotifications(t *testing.T) {
335345

336346
p("MOVING notification test completed successfully")
337347

338-
p("Executing commands and collecting logs for analysis... This will take 10-15 seconds...")
348+
p("Executing commands and collecting logs for analysis... This will take 30 seconds...")
339349
go commandsRunner.FireCommandsUntilStop(ctx)
340-
time.Sleep(10 * time.Second)
350+
time.Sleep(30 * time.Second)
341351
commandsRunner.Stop()
342352
allLogsAnalysis := logCollector.GetAnalysis()
343353
trackerAnalysis := tracker.GetAnalysis()
@@ -436,8 +446,15 @@ func TestPushNotifications(t *testing.T) {
436446
e("Expected no additional handoff retries, got %d", allLogsAnalysis.TotalHandoffRetries-allLogsAnalysis.TotalHandoffCount)
437447
}
438448

439-
p("Analysis complete, no errors found")
449+
if errorsDetected {
450+
logCollector.DumpLogs()
451+
trackerAnalysis.Print(t)
452+
logCollector.Clear()
453+
tracker.Clear()
454+
t.Fatalf("[FAIL] Errors detected in push notification test")
455+
}
440456

457+
p("Analysis complete, no errors found")
441458
// print analysis here, don't dump logs later
442459
dump = false
443460
allLogsAnalysis.Print(t)

0 commit comments

Comments
 (0)