Skip to content

Commit 012d566

Browse files
committed
change output
1 parent 3699acf commit 012d566

File tree

5 files changed

+95
-116
lines changed

5 files changed

+95
-116
lines changed

maintnotifications/e2e/scenario_endpoint_types_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net"
77
"os"
8+
"runtime"
89
"strings"
910
"testing"
1011
"time"
@@ -93,18 +94,20 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
9394
// redefine p and e for each test to get
9495
// proper test name in logs and proper test failures
9596
var p = func(format string, args ...interface{}) {
96-
format = "[%s][ENDPOINT-TYPES] " + format
97+
_, filename, line, _ := runtime.Caller(1)
98+
format = "%s:%d [%s][ENDPOINT-TYPES] " + format + "\n"
9799
ts := time.Now().Format("15:04:05.000")
98-
args = append([]interface{}{ts}, args...)
99-
t.Logf(format, args...)
100+
args = append([]interface{}{filename, line, ts}, args...)
101+
fmt.Printf(format, args...)
100102
}
101103

102104
var e = func(format string, args ...interface{}) {
103105
errorsDetected = true
104-
format = "[%s][ENDPOINT-TYPES][ERROR] " + format
106+
_, filename, line, _ := runtime.Caller(1)
107+
format = "%s:%d [%s][ENDPOINT-TYPES][ERROR] " + format + "\n"
105108
ts := time.Now().Format("15:04:05.000")
106-
args = append([]interface{}{ts}, args...)
107-
t.Errorf(format, args...)
109+
args = append([]interface{}{filename, line, ts}, args...)
110+
fmt.Printf(format, args...)
108111
}
109112

110113
var ef = func(format string, args ...interface{}) {
@@ -146,10 +149,6 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
146149
logger := maintnotifications.NewLoggingHook(int(logging.LogLevelDebug))
147150
setupNotificationHooks(client, tracker, logger)
148151
defer func() {
149-
if dump {
150-
p("Tracker analysis for %s:", endpointTest.name)
151-
tracker.GetAnalysis().Print(t)
152-
}
153152
tracker.Clear()
154153
}()
155154

@@ -218,7 +217,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
218217
if err != nil {
219218
ef("[FI] Failover action failed for %s: %v", endpointTest.name, err)
220219
}
221-
p("[FI] Failover action completed for %s: %s", endpointTest.name, status.Status)
220+
p("[FI] Failover action completed for %s: %v", endpointTest.name, status)
222221

223222
// Test migration with this endpoint type
224223
p("Testing migration with %s endpoint type...", endpointTest.name)
@@ -240,7 +239,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
240239
if err != nil {
241240
ef("[FI] Migrate action failed for %s: %v", endpointTest.name, err)
242241
}
243-
p("[FI] Migrate action completed for %s: %s", endpointTest.name, status.Status)
242+
p("[FI] Migrate action completed for %s: %v", endpointTest.name, status)
244243

245244
// Wait for MIGRATING notification
246245
match, found = logCollector.WaitForLogMatchFunc(func(s string) bool {
@@ -334,7 +333,7 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
334333
if err != nil {
335334
ef("Bind action failed for %s: %v", endpointTest.name, err)
336335
}
337-
p("Bind action completed for %s: %s", endpointTest.name, bindStatus.Status)
336+
p("Bind action completed for %s: %v", endpointTest.name, bindStatus)
338337

339338
// Continue traffic for analysis
340339
time.Sleep(30 * time.Second)
@@ -382,7 +381,6 @@ func TestEndpointTypesPushNotifications(t *testing.T) {
382381
tracker.Clear()
383382
ef("[FAIL] Errors detected with %s endpoint type", endpointTest.name)
384383
}
385-
dump = false
386384
p("Endpoint type %s test completed successfully", endpointTest.name)
387385
logCollector.GetAnalysis().Print(t)
388386
trackerAnalysis.Print(t)

maintnotifications/e2e/scenario_push_notifications_test.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"runtime"
78
"strings"
89
"testing"
910
"time"
@@ -30,21 +31,23 @@ func TestPushNotifications(t *testing.T) {
3031
var found bool
3132

3233
var status *ActionStatusResponse
34+
var errorsDetected = false
3335

3436
var p = func(format string, args ...interface{}) {
35-
format = "[%s][PUSH-NOTIFICATIONS] " + format
37+
_, filename, line, _ := runtime.Caller(1)
38+
format = "%s:%d [%s][PUSH-NOTIFICATIONS] " + format + "\n"
3639
ts := time.Now().Format("15:04:05.000")
37-
args = append([]interface{}{ts}, args...)
38-
t.Logf(format, args...)
40+
args = append([]interface{}{filename, line, ts}, args...)
41+
fmt.Printf(format, args...)
3942
}
4043

41-
var errorsDetected = false
4244
var e = func(format string, args ...interface{}) {
4345
errorsDetected = true
44-
format = "[%s][PUSH-NOTIFICATIONS][ERROR] " + format
46+
_, filename, line, _ := runtime.Caller(1)
47+
format = "%s:%d [%s][PUSH-NOTIFICATIONS][ERROR] " + format + "\n"
4548
ts := time.Now().Format("15:04:05.000")
46-
args = append([]interface{}{ts}, args...)
47-
t.Errorf(format, args...)
49+
args = append([]interface{}{filename, line, ts}, args...)
50+
fmt.Printf(format, args...)
4851
}
4952

5053
var ef = func(format string, args ...interface{}) {
@@ -57,12 +60,6 @@ func TestPushNotifications(t *testing.T) {
5760

5861
logCollector.ClearLogs()
5962
defer func() {
60-
if dump {
61-
p("Dumping logs...")
62-
logCollector.DumpLogs()
63-
p("Log Analysis:")
64-
logCollector.GetAnalysis().Print(t)
65-
}
6663
logCollector.Clear()
6764
}()
6865

@@ -103,10 +100,6 @@ func TestPushNotifications(t *testing.T) {
103100
}
104101

105102
defer func() {
106-
if dump {
107-
p("Pool stats:")
108-
factory.PrintPoolStats(t)
109-
}
110103
factory.DestroyAll()
111104
}()
112105

@@ -115,9 +108,6 @@ func TestPushNotifications(t *testing.T) {
115108
logger := maintnotifications.NewLoggingHook(int(logging.LogLevelDebug))
116109
setupNotificationHooks(client, tracker, logger)
117110
defer func() {
118-
if dump {
119-
tracker.GetAnalysis().Print(t)
120-
}
121111
tracker.Clear()
122112
}()
123113

@@ -188,7 +178,7 @@ func TestPushNotifications(t *testing.T) {
188178
if err != nil {
189179
ef("[FI] Failover action failed: %v", err)
190180
}
191-
fmt.Printf("[FI] Failover action completed: %s\n", status.Status)
181+
p("[FI] Failover action completed: %v", status)
192182

193183
p("FAILING_OVER / FAILED_OVER notifications test completed successfully")
194184

@@ -225,7 +215,7 @@ func TestPushNotifications(t *testing.T) {
225215
if err != nil {
226216
ef("[FI] Migrate action failed: %v", err)
227217
}
228-
fmt.Printf("[FI] Migrate action completed: %s\n", status.Status)
218+
p("[FI] Migrate action completed: %v", status)
229219

230220
go func() {
231221
p("Waiting for MIGRATED notification on conn %d with seqID %d...", connIDToObserve, seqIDToObserve+1)
@@ -401,7 +391,7 @@ func TestPushNotifications(t *testing.T) {
401391
ef("Bind action failed: %v", err)
402392
}
403393

404-
p("Bind action completed: %s", bindStatus.Status)
394+
p("Bind action completed: %v", bindStatus)
405395

406396
p("MOVING notification test completed successfully")
407397

@@ -515,8 +505,6 @@ func TestPushNotifications(t *testing.T) {
515505
}
516506

517507
p("Analysis complete, no errors found")
518-
// print analysis here, don't dump logs later
519-
dump = false
520508
allLogsAnalysis.Print(t)
521509
trackerAnalysis.Print(t)
522510
p("Command runner stats:")

maintnotifications/e2e/scenario_stress_test.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"runtime"
78
"sync"
89
"testing"
910
"time"
@@ -23,21 +24,25 @@ func TestStressPushNotifications(t *testing.T) {
2324
defer cancel()
2425

2526
var dump = true
27+
var errorsDetected = false
28+
2629
var p = func(format string, args ...interface{}) {
27-
format = "[%s][STRESS] " + format
30+
_, filename, line, _ := runtime.Caller(1)
31+
format = "%s:%d [%s][STRESS] " + format + "\n"
2832
ts := time.Now().Format("15:04:05.000")
29-
args = append([]interface{}{ts}, args...)
30-
t.Logf(format, args...)
33+
args = append([]interface{}{filename, line, ts}, args...)
34+
fmt.Printf(format, args...)
3135
}
3236

33-
var errorsDetected = false
3437
var e = func(format string, args ...interface{}) {
3538
errorsDetected = true
36-
format = "[%s][STRESS][ERROR] " + format
39+
_, filename, line, _ := runtime.Caller(1)
40+
format = "%s:%d [%s][STRESS][ERROR] " + format + "\n"
3741
ts := time.Now().Format("15:04:05.000")
38-
args = append([]interface{}{ts}, args...)
39-
t.Errorf(format, args...)
42+
args = append([]interface{}{filename, line, ts}, args...)
43+
fmt.Printf(format, args...)
4044
}
45+
4146
var ef = func(format string, args ...interface{}) {
4247
errorsDetected = true
4348
format = "[%s][STRESS][ERROR] " + format
@@ -48,12 +53,6 @@ func TestStressPushNotifications(t *testing.T) {
4853

4954
logCollector.ClearLogs()
5055
defer func() {
51-
if dump {
52-
p("Dumping logs...")
53-
logCollector.DumpLogs()
54-
p("Log Analysis:")
55-
logCollector.GetAnalysis().Print(t)
56-
}
5756
logCollector.Clear()
5857
}()
5958

@@ -118,10 +117,6 @@ func TestStressPushNotifications(t *testing.T) {
118117
if dump {
119118
p("Pool stats:")
120119
factory.PrintPoolStats(t)
121-
for i, tracker := range trackers {
122-
p("Stress client %d analysis:", i)
123-
tracker.GetAnalysis().Print(t)
124-
}
125120
}
126121
for _, runner := range commandRunners {
127122
runner.Stop()
@@ -195,7 +190,7 @@ func TestStressPushNotifications(t *testing.T) {
195190
resp, err = faultInjector.TriggerAction(ctx, ActionRequest{
196191
Type: "migrate",
197192
Parameters: map[string]interface{}{
198-
"bdb_id": endpointConfig.BdbID,
193+
"bdb_id": endpointConfig.BdbID,
199194
},
200195
})
201196
}
@@ -297,6 +292,15 @@ func TestStressPushNotifications(t *testing.T) {
297292

298293
if errorsDetected {
299294
ef("Errors detected under stress")
295+
logCollector.DumpLogs()
296+
for i, tracker := range trackers {
297+
p("=== Stress Client %d Analysis ===", i)
298+
tracker.GetAnalysis().Print(t)
299+
}
300+
logCollector.Clear()
301+
for _, tracker := range trackers {
302+
tracker.Clear()
303+
}
300304
}
301305

302306
dump = false

maintnotifications/e2e/scenario_timeout_configs_test.go

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"runtime"
78
"strings"
89
"testing"
910
"time"
@@ -23,11 +24,23 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
2324
defer cancel()
2425

2526
var dump = true
27+
28+
var errorsDetected = false
2629
var p = func(format string, args ...interface{}) {
27-
format = "[%s][TIMEOUT-CONFIGS] " + format
30+
_, filename, line, _ := runtime.Caller(1)
31+
format = "%s:%d [%s][TIMEOUT-CONFIGS] " + format + "\n"
2832
ts := time.Now().Format("15:04:05.000")
29-
args = append([]interface{}{ts}, args...)
30-
t.Logf(format, args...)
33+
args = append([]interface{}{filename, line, ts}, args...)
34+
fmt.Printf(format, args...)
35+
}
36+
37+
var e = func(format string, args ...interface{}) {
38+
errorsDetected = true
39+
_, filename, line, _ := runtime.Caller(1)
40+
format = "%s:%d [%s][TIMEOUT-CONFIGS][ERROR] " + format + "\n"
41+
ts := time.Now().Format("15:04:05.000")
42+
args = append([]interface{}{filename, line, ts}, args...)
43+
fmt.Printf(format, args...)
3144
}
3245

3346
// Test different timeout configurations
@@ -67,12 +80,6 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
6780

6881
logCollector.ClearLogs()
6982
defer func() {
70-
if dump {
71-
p("Dumping logs...")
72-
logCollector.DumpLogs()
73-
p("Log Analysis:")
74-
logCollector.GetAnalysis().Print(t)
75-
}
7683
logCollector.Clear()
7784
}()
7885

@@ -100,22 +107,7 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
100107
// Test each timeout configuration
101108
for _, timeoutTest := range timeoutConfigs {
102109
t.Run(timeoutTest.name, func(t *testing.T) {
103-
// redefine p and e for each test to get
104-
// proper test name in logs and proper test failures
105-
var p = func(format string, args ...interface{}) {
106-
format = "[%s][TIMEOUT-CONFIGS] " + format
107-
ts := time.Now().Format("15:04:05.000")
108-
args = append([]interface{}{ts}, args...)
109-
t.Logf(format, args...)
110-
}
111-
112-
var e = func(format string, args ...interface{}) {
113-
format = "[%s][TIMEOUT-CONFIGS][ERROR] " + format
114-
ts := time.Now().Format("15:04:05.000")
115-
args = append([]interface{}{ts}, args...)
116-
t.Errorf(format, args...)
117-
}
118-
110+
errorsDetected = false
119111
var ef = func(format string, args ...interface{}) {
120112
format = "[%s][TIMEOUT-CONFIGS][ERROR] " + format
121113
ts := time.Now().Format("15:04:05.000")
@@ -157,10 +149,6 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
157149
logger := maintnotifications.NewLoggingHook(int(logging.LogLevelDebug))
158150
setupNotificationHooks(client, tracker, logger)
159151
defer func() {
160-
if dump {
161-
p("Tracker analysis for %s:", timeoutTest.name)
162-
tracker.GetAnalysis().Print(t)
163-
}
164152
tracker.Clear()
165153
}()
166154

@@ -271,7 +259,6 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
271259
migrateData := logs2.ExtractDataFromLogMessage(match)
272260
p("MIGRATING notification received for %s: %v", timeoutTest.name, migrateData)
273261

274-
275262
// do a bind action
276263
bindResp, err := faultInjector.TriggerAction(ctx, ActionRequest{
277264
Type: "bind",
@@ -358,6 +345,13 @@ func TestTimeoutConfigurationsPushNotifications(t *testing.T) {
358345
e("Expected successful handoffs with %s config, got none", timeoutTest.name)
359346
}
360347

348+
if errorsDetected {
349+
logCollector.DumpLogs()
350+
trackerAnalysis.Print(t)
351+
logCollector.Clear()
352+
tracker.Clear()
353+
ef("[FAIL] Errors detected with %s timeout config", timeoutTest.name)
354+
}
361355
p("Timeout configuration %s test completed successfully in %v", timeoutTest.name, testDuration)
362356
p("Command runner stats:")
363357
p("Operations: %d, Errors: %d, Timeout Errors: %d",

0 commit comments

Comments
 (0)