Skip to content

Commit 72cf032

Browse files
committed
improve logging for debug purposes of tests
1 parent 7b098fa commit 72cf032

File tree

5 files changed

+117
-72
lines changed

5 files changed

+117
-72
lines changed

maintnotifications/e2e/scenario_endpoint_types_test.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
7070
// Create fault injector
7171
faultInjector, err := CreateTestFaultInjector()
7272
if err != nil {
73-
t.Fatalf("Failed to create fault injector: %v", err)
73+
t.Fatalf("[ERROR] Failed to create fault injector: %v", err)
7474
}
7575

7676
defer func() {
@@ -103,6 +103,15 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
103103
args = append([]interface{}{ts}, args...)
104104
t.Errorf(format, args...)
105105
}
106+
107+
var ef = func(format string, args ...interface{}) {
108+
errorsDetected = true
109+
format = "[%s][ENDPOINT-TYPES][ERROR] " + format
110+
ts := time.Now().Format("15:04:05.000")
111+
args = append([]interface{}{ts}, args...)
112+
t.Fatalf(format, args...)
113+
}
114+
106115
p("Testing endpoint type: %s - %s", endpointTest.name, endpointTest.description)
107116

108117
minIdleConns := 3
@@ -126,7 +135,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
126135
ClientName: fmt.Sprintf("endpoint-test-%s", endpointTest.name),
127136
})
128137
if err != nil {
129-
t.Fatalf("Failed to create client for %s: %v", endpointTest.name, err)
138+
ef("Failed to create client for %s: %v", endpointTest.name, err)
130139
}
131140

132141
// Create timeout tracker
@@ -144,7 +153,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
144153
// Verify initial connectivity
145154
err = client.Ping(ctx).Err()
146155
if err != nil {
147-
t.Fatalf("Failed to ping Redis with %s endpoint type: %v", endpointTest.name, err)
156+
ef("Failed to ping Redis with %s endpoint type: %v", endpointTest.name, err)
148157
}
149158

150159
p("Client connected successfully with %s endpoint type", endpointTest.name)
@@ -169,7 +178,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
169178
},
170179
})
171180
if err != nil {
172-
t.Fatalf("Failed to trigger failover action for %s: %v", endpointTest.name, err)
181+
ef("Failed to trigger failover action for %s: %v", endpointTest.name, err)
173182
}
174183

175184
// Start command traffic
@@ -182,7 +191,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
182191
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "FAILING_OVER")
183192
}, 2*time.Minute)
184193
if !found {
185-
t.Fatalf("FAILING_OVER notification was not received for %s endpoint type", endpointTest.name)
194+
ef("FAILING_OVER notification was not received for %s endpoint type", endpointTest.name)
186195
}
187196
failingOverData := logs2.ExtractDataFromLogMessage(match)
188197
p("FAILING_OVER notification received for %s. %v", endpointTest.name, failingOverData)
@@ -194,7 +203,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
194203
return notificationType(s, "FAILED_OVER") && connID(s, connIDToObserve) && seqID(s, seqIDToObserve+1)
195204
}, 2*time.Minute)
196205
if !found {
197-
t.Fatalf("FAILED_OVER notification was not received for %s endpoint type", endpointTest.name)
206+
ef("FAILED_OVER notification was not received for %s endpoint type", endpointTest.name)
198207
}
199208
failedOverData := logs2.ExtractDataFromLogMessage(match)
200209
p("FAILED_OVER notification received for %s. %v", endpointTest.name, failedOverData)
@@ -205,7 +214,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
205214
WithPollInterval(1*time.Second),
206215
)
207216
if err != nil {
208-
t.Fatalf("[FI] Failover action failed for %s: %v", endpointTest.name, err)
217+
ef("[FI] Failover action failed for %s: %v", endpointTest.name, err)
209218
}
210219
p("[FI] Failover action completed for %s: %s", endpointTest.name, status.Status)
211220

@@ -218,15 +227,15 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
218227
},
219228
})
220229
if err != nil {
221-
t.Fatalf("Failed to trigger migrate action for %s: %v", endpointTest.name, err)
230+
ef("Failed to trigger migrate action for %s: %v", endpointTest.name, err)
222231
}
223232

224233
// Wait for MIGRATING notification
225234
match, found = logCollector.WaitForLogMatchFunc(func(s string) bool {
226235
return strings.Contains(s, logs2.ProcessingNotificationMessage) && strings.Contains(s, "MIGRATING")
227236
}, 30*time.Second)
228237
if !found {
229-
t.Fatalf("MIGRATING notification was not received for %s endpoint type", endpointTest.name)
238+
ef("MIGRATING notification was not received for %s endpoint type", endpointTest.name)
230239
}
231240
migrateData := logs2.ExtractDataFromLogMessage(match)
232241
p("MIGRATING notification received for %s: %v", endpointTest.name, migrateData)
@@ -237,7 +246,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
237246
WithPollInterval(1*time.Second),
238247
)
239248
if err != nil {
240-
t.Fatalf("[FI] Migrate action failed for %s: %v", endpointTest.name, err)
249+
ef("[FI] Migrate action failed for %s: %v", endpointTest.name, err)
241250
}
242251
p("[FI] Migrate action completed for %s: %s", endpointTest.name, status.Status)
243252

@@ -248,7 +257,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
248257
return notificationType(s, "MIGRATED") && connID(s, connIDToObserve) && seqID(s, seqIDToObserve+1)
249258
}, 2*time.Minute)
250259
if !found {
251-
t.Fatalf("MIGRATED notification was not received for %s endpoint type", endpointTest.name)
260+
ef("MIGRATED notification was not received for %s endpoint type", endpointTest.name)
252261
}
253262
migratedData := logs2.ExtractDataFromLogMessage(match)
254263
p("MIGRATED notification received for %s. %v", endpointTest.name, migratedData)
@@ -262,15 +271,15 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
262271
},
263272
})
264273
if err != nil {
265-
t.Fatalf("Failed to trigger bind action for %s: %v", endpointTest.name, err)
274+
ef("Failed to trigger bind action for %s: %v", endpointTest.name, err)
266275
}
267276

268277
// Wait for MOVING notification
269278
match, found = logCollector.MatchOrWaitForLogMatchFunc(func(s string) bool {
270279
return strings.Contains(s, logs2.ProcessingNotificationMessage) && notificationType(s, "MOVING")
271280
}, 2*time.Minute)
272281
if !found {
273-
t.Fatalf("MOVING notification was not received for %s endpoint type", endpointTest.name)
282+
ef("MOVING notification was not received for %s endpoint type", endpointTest.name)
274283
}
275284
movingData := logs2.ExtractDataFromLogMessage(match)
276285
p("MOVING notification received for %s. %v", endpointTest.name, movingData)
@@ -322,7 +331,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
322331
WithMaxWaitTime(120*time.Second),
323332
WithPollInterval(2*time.Second))
324333
if err != nil {
325-
t.Fatalf("Bind action failed for %s: %v", endpointTest.name, err)
334+
ef("Bind action failed for %s: %v", endpointTest.name, err)
326335
}
327336
p("Bind action completed for %s: %s", endpointTest.name, bindStatus.Status)
328337

@@ -370,7 +379,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
370379
trackerAnalysis.Print(t)
371380
logCollector.Clear()
372381
tracker.Clear()
373-
t.Fatalf("[FAIL] Errors detected with %s endpoint type", endpointTest.name)
382+
ef("[FAIL] Errors detected with %s endpoint type", endpointTest.name)
374383
}
375384
dump = false
376385
p("Endpoint type %s test completed successfully", endpointTest.name)

maintnotifications/e2e/scenario_push_notifications_test.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestPushNotifications(t *testing.T) {
3232
var status *ActionStatusResponse
3333

3434
var p = func(format string, args ...interface{}) {
35-
format = "[%s] " + format
35+
format = "[%s][PUSH-NOTIFICATIONS] " + format
3636
ts := time.Now().Format("15:04:05.000")
3737
args = append([]interface{}{ts}, args...)
3838
t.Logf(format, args...)
@@ -41,12 +41,20 @@ func TestPushNotifications(t *testing.T) {
4141
var errorsDetected = false
4242
var e = func(format string, args ...interface{}) {
4343
errorsDetected = true
44-
format = "[%s][ERROR] " + format
44+
format = "[%s][PUSH-NOTIFICATIONS][ERROR] " + format
4545
ts := time.Now().Format("15:04:05.000")
4646
args = append([]interface{}{ts}, args...)
4747
t.Errorf(format, args...)
4848
}
4949

50+
var ef = func(format string, args ...interface{}) {
51+
errorsDetected = true
52+
format = "[%s][PUSH-NOTIFICATIONS][ERROR] " + format
53+
ts := time.Now().Format("15:04:05.000")
54+
args = append([]interface{}{ts}, args...)
55+
t.Fatalf(format, args...)
56+
}
57+
5058
logCollector.ClearLogs()
5159
defer func() {
5260
if dump {
@@ -61,14 +69,14 @@ func TestPushNotifications(t *testing.T) {
6169
// Create client factory from configuration
6270
factory, err := CreateTestClientFactory("standalone")
6371
if err != nil {
64-
t.Skipf("Enterprise cluster not available, skipping push notification tests: %v", err)
72+
t.Skipf("[PUSH-NOTIFICATIONS][SKIP] Enterprise cluster not available, skipping push notification tests: %v", err)
6573
}
6674
endpointConfig := factory.GetConfig()
6775

6876
// Create fault injector
6977
faultInjector, err := CreateTestFaultInjector()
7078
if err != nil {
71-
t.Fatalf("Failed to create fault injector: %v", err)
79+
ef("Failed to create fault injector: %v", err)
7280
}
7381

7482
minIdleConns := 5
@@ -91,7 +99,7 @@ func TestPushNotifications(t *testing.T) {
9199
ClientName: "push-notification-test-client",
92100
})
93101
if err != nil {
94-
t.Fatalf("Failed to create client: %v", err)
102+
ef("Failed to create client: %v", err)
95103
}
96104

97105
defer func() {
@@ -116,7 +124,7 @@ func TestPushNotifications(t *testing.T) {
116124
// Verify initial connectivity
117125
err = client.Ping(ctx).Err()
118126
if err != nil {
119-
t.Fatalf("Failed to ping Redis: %v", err)
127+
ef("Failed to ping Redis: %v", err)
120128
}
121129

122130
p("Client connected successfully, starting push notification test")
@@ -143,7 +151,7 @@ func TestPushNotifications(t *testing.T) {
143151
},
144152
})
145153
if err != nil {
146-
t.Fatalf("Failed to trigger failover action: %v", err)
154+
ef("Failed to trigger failover action: %v", err)
147155
}
148156
go func() {
149157
p("Waiting for FAILING_OVER notification")
@@ -154,7 +162,7 @@ func TestPushNotifications(t *testing.T) {
154162
}()
155163
commandsRunner.FireCommandsUntilStop(ctx)
156164
if !found {
157-
t.Fatal("FAILING_OVER notification was not received within 2 minutes")
165+
ef("FAILING_OVER notification was not received within 2 minutes")
158166
}
159167
failingOverData := logs2.ExtractDataFromLogMessage(match)
160168
p("FAILING_OVER notification received. %v", failingOverData)
@@ -169,7 +177,7 @@ func TestPushNotifications(t *testing.T) {
169177
}()
170178
commandsRunner.FireCommandsUntilStop(ctx)
171179
if !found {
172-
t.Fatal("FAILED_OVER notification was not received within 2 minutes")
180+
ef("FAILED_OVER notification was not received within 2 minutes")
173181
}
174182
failedOverData := logs2.ExtractDataFromLogMessage(match)
175183
p("FAILED_OVER notification received. %v", failedOverData)
@@ -179,7 +187,7 @@ func TestPushNotifications(t *testing.T) {
179187
WithPollInterval(1*time.Second),
180188
)
181189
if err != nil {
182-
t.Fatalf("[FI] Failover action failed: %v", err)
190+
ef("[FI] Failover action failed: %v", err)
183191
}
184192
fmt.Printf("[FI] Failover action completed: %s\n", status.Status)
185193

@@ -194,7 +202,7 @@ func TestPushNotifications(t *testing.T) {
194202
},
195203
})
196204
if err != nil {
197-
t.Fatalf("Failed to trigger migrate action: %v", err)
205+
ef("Failed to trigger migrate action: %v", err)
198206
}
199207
go func() {
200208
match, found = logCollector.WaitForLogMatchFunc(func(s string) bool {
@@ -204,7 +212,7 @@ func TestPushNotifications(t *testing.T) {
204212
}()
205213
commandsRunner.FireCommandsUntilStop(ctx)
206214
if !found {
207-
t.Fatal("MIGRATING notification for migrate action was not received within 20 seconds")
215+
ef("MIGRATING notification for migrate action was not received within 20 seconds")
208216
}
209217
migrateData := logs2.ExtractDataFromLogMessage(match)
210218
seqIDToObserve = int64(migrateData["seqID"].(float64))
@@ -216,7 +224,7 @@ func TestPushNotifications(t *testing.T) {
216224
WithPollInterval(1*time.Second),
217225
)
218226
if err != nil {
219-
t.Fatalf("[FI] Migrate action failed: %v", err)
227+
ef("[FI] Migrate action failed: %v", err)
220228
}
221229
fmt.Printf("[FI] Migrate action completed: %s\n", status.Status)
222230

@@ -229,7 +237,7 @@ func TestPushNotifications(t *testing.T) {
229237
}()
230238
commandsRunner.FireCommandsUntilStop(ctx)
231239
if !found {
232-
t.Fatal("MIGRATED notification was not received within 2 minutes")
240+
ef("MIGRATED notification was not received within 2 minutes")
233241
}
234242
migratedData := logs2.ExtractDataFromLogMessage(match)
235243
p("MIGRATED notification received. %v", migratedData)
@@ -247,7 +255,7 @@ func TestPushNotifications(t *testing.T) {
247255
},
248256
})
249257
if err != nil {
250-
t.Fatalf("Failed to trigger bind action: %v", err)
258+
ef("Failed to trigger bind action: %v", err)
251259
}
252260

253261
// start a second client but don't execute any commands on it
@@ -269,7 +277,7 @@ func TestPushNotifications(t *testing.T) {
269277
})
270278

271279
if err != nil {
272-
t.Fatalf("failed to create client: %v", err)
280+
ef("failed to create client: %v", err)
273281
}
274282
// setup tracking for second client
275283
tracker2 := NewTrackingNotificationsHook()
@@ -336,15 +344,15 @@ func TestPushNotifications(t *testing.T) {
336344

337345
// Wait for the goroutine to complete and check for errors
338346
if err := <-errChan; err != nil {
339-
t.Fatalf("Second client goroutine error: %v", err)
347+
ef("Second client goroutine error: %v", err)
340348
}
341349

342350
// Wait for bind action to complete
343351
bindStatus, err := faultInjector.WaitForAction(ctx, bindResp.ActionID,
344352
WithMaxWaitTime(120*time.Second),
345353
WithPollInterval(2*time.Second))
346354
if err != nil {
347-
t.Fatalf("Bind action failed: %v", err)
355+
ef("Bind action failed: %v", err)
348356
}
349357

350358
p("Bind action completed: %s", bindStatus.Status)
@@ -457,7 +465,7 @@ func TestPushNotifications(t *testing.T) {
457465
trackerAnalysis.Print(t)
458466
logCollector.Clear()
459467
tracker.Clear()
460-
t.Fatalf("[FAIL] Errors detected in push notification test")
468+
ef("[FAIL] Errors detected in push notification test")
461469
}
462470

463471
p("Analysis complete, no errors found")

0 commit comments

Comments
 (0)