Skip to content

Commit 0f908f6

Browse files
committed
cleanup
1 parent 7c045e4 commit 0f908f6

15 files changed

+92
-2045
lines changed

e2e.test

-10 MB
Binary file not shown.

internal/maintnotifications/logs/log_messages_test.go

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"regexp"
88
"strings"
99
"testing"
10+
11+
"github.com/redis/go-redis/v9/internal"
1012
)
1113

1214
// validateJSONInLogMessage extracts and validates JSON from a log message
@@ -48,8 +50,13 @@ func validateJSONInLogMessage(t *testing.T, logMessage string, expectedData map[
4850
}
4951

5052
func TestHandoffLogFunctions(t *testing.T) {
53+
// Set debug level for testing
54+
oldLogLevel := internal.LogLevel
55+
internal.LogLevel = 3 // Debug level
56+
defer func() { internal.LogLevel = oldLogLevel }()
57+
5158
t.Run("HandoffStarted", func(t *testing.T) {
52-
result := HandoffStarted(LogLevelDebug, 123, "localhost:6379")
59+
result := HandoffStarted(123, "localhost:6379")
5360
if !strings.Contains(result, "conn[123] handoff started to localhost:6379") {
5461
t.Errorf("Expected message to contain handoff started text, got: %s", result)
5562
}
@@ -61,7 +68,7 @@ func TestHandoffLogFunctions(t *testing.T) {
6168

6269
t.Run("HandoffFailed", func(t *testing.T) {
6370
err := errors.New("connection refused")
64-
result := HandoffFailed(LogLevelDebug, 123, "localhost:6379", 2, 3, err)
71+
result := HandoffFailed(123, "localhost:6379", 2, 3, err)
6572
if !strings.Contains(result, "conn[123] handoff failed to localhost:6379 (attempt 2/3): connection refused") {
6673
t.Errorf("Expected message to contain handoff failed text, got: %s", result)
6774
}
@@ -75,7 +82,7 @@ func TestHandoffLogFunctions(t *testing.T) {
7582
})
7683

7784
t.Run("HandoffSucceeded", func(t *testing.T) {
78-
result := HandoffSucceeded(LogLevelDebug, 123, "localhost:6379")
85+
result := HandoffSucceeded(123, "localhost:6379")
7986
if !strings.Contains(result, "conn[123] handoff succeeded to localhost:6379") {
8087
t.Errorf("Expected message to contain handoff succeeded text, got: %s", result)
8188
}
@@ -87,24 +94,29 @@ func TestHandoffLogFunctions(t *testing.T) {
8794
}
8895

8996
func TestTimeoutLogFunctions(t *testing.T) {
97+
// Set debug level for testing
98+
oldLogLevel := internal.LogLevel
99+
internal.LogLevel = 3 // Debug level
100+
defer func() { internal.LogLevel = oldLogLevel }()
101+
90102
t.Run("RelaxedTimeoutDueToNotification", func(t *testing.T) {
91-
result := RelaxedTimeoutDueToNotification(LogLevelDebug, 123, "MIGRATING", "10s")
103+
result := RelaxedTimeoutDueToNotification(123, "MIGRATING", "10s")
92104
expected := "conn[123] applying relaxed timeout due to notification MIGRATING (10s) {\"connID\":123,\"notificationType\":\"MIGRATING\",\"timeout\":\"10s\"}"
93105
if result != expected {
94106
t.Errorf("Expected %q, got %q", expected, result)
95107
}
96108
})
97109

98110
t.Run("UnrelaxedTimeout", func(t *testing.T) {
99-
result := UnrelaxedTimeout(LogLevelDebug, 123)
111+
result := UnrelaxedTimeout(123)
100112
expected := "conn[123] clearing relaxed timeout {\"connID\":123}"
101113
if result != expected {
102114
t.Errorf("Expected %q, got %q", expected, result)
103115
}
104116
})
105117

106118
t.Run("UnrelaxedTimeoutAfterDeadline", func(t *testing.T) {
107-
result := UnrelaxedTimeoutAfterDeadline(LogLevelDebug, 123)
119+
result := UnrelaxedTimeoutAfterDeadline(123)
108120
expected := "conn[123] clearing relaxed timeout after deadline {\"connID\":123}"
109121
if result != expected {
110122
t.Errorf("Expected %q, got %q", expected, result)
@@ -148,23 +160,28 @@ func TestHandoffQueueLogFunctions(t *testing.T) {
148160
}
149161

150162
func TestNotificationLogFunctions(t *testing.T) {
163+
// Set debug level for testing
164+
oldLogLevel := internal.LogLevel
165+
internal.LogLevel = 3 // Debug level
166+
defer func() { internal.LogLevel = oldLogLevel }()
167+
151168
t.Run("ProcessingNotification", func(t *testing.T) {
152-
result := ProcessingNotification(LogLevelDebug, 123, 1, "MOVING", []interface{}{"MOVING", "slot_data"})
169+
result := ProcessingNotification(123, 1, "MOVING", []interface{}{"MOVING", "slot_data"})
153170
if !strings.Contains(result, "conn[123] seqId[1] processing notification MOVING:") {
154171
t.Errorf("Expected message to contain processing notification, got %q", result)
155172
}
156173
})
157174

158175
t.Run("ProcessingNotificationFailed", func(t *testing.T) {
159176
err := errors.New("invalid notification")
160-
result := ProcessingNotificationFailed(LogLevelDebug, 123, "MOVING", err, []interface{}{"MOVING"})
177+
result := ProcessingNotificationFailed(123, "MOVING", err, []interface{}{"MOVING"})
161178
if !strings.Contains(result, "conn[123] failed to process notification MOVING: invalid notification") {
162179
t.Errorf("Expected message to contain failed processing, got %q", result)
163180
}
164181
})
165182

166183
t.Run("ProcessingNotificationSucceeded", func(t *testing.T) {
167-
result := ProcessingNotificationSucceeded(LogLevelDebug, 123, "MOVING")
184+
result := ProcessingNotificationSucceeded(123, "MOVING")
168185
expected := "conn[123] processed notification successfully MOVING {\"connID\":123,\"notificationType\":\"MOVING\"}"
169186
if result != expected {
170187
t.Errorf("Expected %q, got %q", expected, result)
@@ -173,32 +190,37 @@ func TestNotificationLogFunctions(t *testing.T) {
173190
}
174191

175192
func TestMovingOperationLogFunctions(t *testing.T) {
193+
// Set debug level for testing
194+
oldLogLevel := internal.LogLevel
195+
internal.LogLevel = 3 // Debug level
196+
defer func() { internal.LogLevel = oldLogLevel }()
197+
176198
t.Run("DuplicateMovingOperation", func(t *testing.T) {
177-
result := DuplicateMovingOperation(LogLevelDebug, 123, "localhost:6379", 456)
199+
result := DuplicateMovingOperation(123, "localhost:6379", 456)
178200
expected := "conn[123] duplicate MOVING operation ignored for localhost:6379 (seqID: 456) {\"connID\":123,\"endpoint\":\"localhost:6379\",\"seqID\":456}"
179201
if result != expected {
180202
t.Errorf("Expected %q, got %q", expected, result)
181203
}
182204
})
183205

184206
t.Run("TrackingMovingOperation", func(t *testing.T) {
185-
result := TrackingMovingOperation(LogLevelDebug, 123, "localhost:6379", 456)
207+
result := TrackingMovingOperation(123, "localhost:6379", 456)
186208
expected := "conn[123] tracking MOVING operation for localhost:6379 (seqID: 456) {\"connID\":123,\"endpoint\":\"localhost:6379\",\"seqID\":456}"
187209
if result != expected {
188210
t.Errorf("Expected %q, got %q", expected, result)
189211
}
190212
})
191213

192214
t.Run("UntrackingMovingOperation", func(t *testing.T) {
193-
result := UntrackingMovingOperation(LogLevelDebug, 123, 456)
215+
result := UntrackingMovingOperation(123, 456)
194216
expected := "conn[123] untracking MOVING operation (seqID: 456) {\"connID\":123,\"seqID\":456}"
195217
if result != expected {
196218
t.Errorf("Expected %q, got %q", expected, result)
197219
}
198220
})
199221

200222
t.Run("OperationNotTracked", func(t *testing.T) {
201-
result := OperationNotTracked(LogLevelDebug, 123, 456)
223+
result := OperationNotTracked(123, 456)
202224
expected := "conn[123] operation not tracked (seqID: 456) {\"connID\":123,\"seqID\":456}"
203225
if result != expected {
204226
t.Errorf("Expected %q, got %q", expected, result)
@@ -207,15 +229,20 @@ func TestMovingOperationLogFunctions(t *testing.T) {
207229
}
208230

209231
func TestConditionalJSONLogging(t *testing.T) {
232+
oldLogLevel := internal.LogLevel
233+
defer func() { internal.LogLevel = oldLogLevel }()
234+
210235
t.Run("DebugLevel_IncludesJSON", func(t *testing.T) {
211-
result := HandoffStarted(LogLevelDebug, 123, "localhost:6379")
236+
internal.LogLevel = 3 // Debug level
237+
result := HandoffStarted(123, "localhost:6379")
212238
if !strings.Contains(result, "{\"connID\":123,\"endpoint\":\"localhost:6379\"}") {
213239
t.Errorf("Expected JSON to be included at Debug level, got: %s", result)
214240
}
215241
})
216242

217243
t.Run("ErrorLevel_ExcludesJSON", func(t *testing.T) {
218-
result := HandoffStarted(LogLevelError, 123, "localhost:6379")
244+
internal.LogLevel = 0 // Error level
245+
result := HandoffStarted(123, "localhost:6379")
219246
if strings.Contains(result, "{") {
220247
t.Errorf("Expected JSON to be excluded at Error level, got: %s", result)
221248
}
@@ -226,11 +253,12 @@ func TestConditionalJSONLogging(t *testing.T) {
226253
})
227254

228255
t.Run("InfoLevel_ExcludesJSON", func(t *testing.T) {
229-
result := DuplicateMovingOperation(LogLevelInfo, 123, "localhost:6379", 456)
256+
internal.LogLevel = 2 // Info level
257+
result := DuplicateMovingOperation(123, "localhost:6379", 456)
230258
if strings.Contains(result, "{") {
231259
t.Errorf("Expected JSON to be excluded at Info level, got: %s", result)
232260
}
233-
expected := "conn[123] duplicate MOVING operation ignored for localhost:6379 (seqID: 456)"
261+
expected := "conn[123] duplicate MOVING operation ignored for localhost:6379 seqID[456]"
234262
if result != expected {
235263
t.Errorf("Expected %q, got %q", expected, result)
236264
}
@@ -306,30 +334,35 @@ func TestConnectionStateLogFunctions(t *testing.T) {
306334

307335
// TestAllFunctionsHaveStructuredFormat ensures all log functions have structured format
308336
func TestAllFunctionsHaveStructuredFormat(t *testing.T) {
337+
// Set debug level for testing
338+
oldLogLevel := internal.LogLevel
339+
internal.LogLevel = 3 // Debug level
340+
defer func() { internal.LogLevel = oldLogLevel }()
341+
309342
testCases := []struct {
310343
name string
311344
function func() string
312345
}{
313-
{"HandoffStarted", func() string { return HandoffStarted(LogLevelDebug, 1, "test") }},
314-
{"HandoffFailed", func() string { return HandoffFailed(LogLevelDebug, 1, "test", 1, 3, errors.New("test")) }},
315-
{"HandoffSucceeded", func() string { return HandoffSucceeded(LogLevelDebug, 1, "test") }},
316-
{"RelaxedTimeoutDueToNotification", func() string { return RelaxedTimeoutDueToNotification(LogLevelDebug, 1, "TEST", "5s") }},
346+
{"HandoffStarted", func() string { return HandoffStarted(1, "test") }},
347+
{"HandoffFailed", func() string { return HandoffFailed(1, "test", 1, 3, errors.New("test")) }},
348+
{"HandoffSucceeded", func() string { return HandoffSucceeded(1, "test") }},
349+
{"RelaxedTimeoutDueToNotification", func() string { return RelaxedTimeoutDueToNotification(1, "TEST", "5s") }},
317350

318-
{"UnrelaxedTimeout", func() string { return UnrelaxedTimeout(LogLevelDebug, 1) }},
319-
{"UnrelaxedTimeoutAfterDeadline", func() string { return UnrelaxedTimeoutAfterDeadline(LogLevelDebug, 1) }},
351+
{"UnrelaxedTimeout", func() string { return UnrelaxedTimeout(1) }},
352+
{"UnrelaxedTimeoutAfterDeadline", func() string { return UnrelaxedTimeoutAfterDeadline(1) }},
320353
{"HandoffQueueFull", func() string { return HandoffQueueFull(1, 10) }},
321354
{"FailedToQueueHandoff", func() string { return FailedToQueueHandoff(1, errors.New("test")) }},
322355
{"ConnectionAlreadyMarkedForHandoff", func() string { return ConnectionAlreadyMarkedForHandoff(1) }},
323356
{"ReachedMaxHandoffRetries", func() string { return ReachedMaxHandoffRetries(1, "test", 3) }},
324-
{"ProcessingNotification", func() string { return ProcessingNotification(LogLevelDebug, 1, 2, "TEST", "data") }},
357+
{"ProcessingNotification", func() string { return ProcessingNotification(1, 2, "TEST", "data") }},
325358
{"ProcessingNotificationFailed", func() string {
326-
return ProcessingNotificationFailed(LogLevelDebug, 1, "TEST", errors.New("test"), "data")
359+
return ProcessingNotificationFailed(1, "TEST", errors.New("test"), "data")
327360
}},
328-
{"ProcessingNotificationSucceeded", func() string { return ProcessingNotificationSucceeded(LogLevelDebug, 1, "TEST") }},
329-
{"DuplicateMovingOperation", func() string { return DuplicateMovingOperation(LogLevelDebug, 1, "test", 1) }},
330-
{"TrackingMovingOperation", func() string { return TrackingMovingOperation(LogLevelDebug, 1, "test", 1) }},
331-
{"UntrackingMovingOperation", func() string { return UntrackingMovingOperation(LogLevelDebug, 1, 1) }},
332-
{"OperationNotTracked", func() string { return OperationNotTracked(LogLevelDebug, 1, 1) }},
361+
{"ProcessingNotificationSucceeded", func() string { return ProcessingNotificationSucceeded(1, "TEST") }},
362+
{"DuplicateMovingOperation", func() string { return DuplicateMovingOperation(1, "test", 1) }},
363+
{"TrackingMovingOperation", func() string { return TrackingMovingOperation(1, "test", 1) }},
364+
{"UntrackingMovingOperation", func() string { return UntrackingMovingOperation(1, 1) }},
365+
{"OperationNotTracked", func() string { return OperationNotTracked(1, 1) }},
333366
{"RemovingConnectionFromPool", func() string { return RemovingConnectionFromPool(1, errors.New("test")) }},
334367
{"NoPoolProvidedCannotRemove", func() string { return NoPoolProvidedCannotRemove(1, errors.New("test")) }},
335368
{"CircuitBreakerOpen", func() string { return CircuitBreakerOpen(1, "test") }},
@@ -338,8 +371,8 @@ func TestAllFunctionsHaveStructuredFormat(t *testing.T) {
338371
{"ShuttingDown", func() string { return ShuttingDown() }},
339372
{"ConnectionInInvalidStateForHandoff", func() string { return ConnectionInInvalidStateForHandoff(1, "test") }},
340373

341-
{"HandoffStarted", func() string { return HandoffStarted(LogLevelDebug, 1, "localhost:6379") }},
342-
{"HandoffFailed", func() string { return HandoffFailed(LogLevelDebug, 1, "localhost:6379", 1, 3, errors.New("test")) }},
374+
{"HandoffStarted", func() string { return HandoffStarted(1, "localhost:6379") }},
375+
{"HandoffFailed", func() string { return HandoffFailed(1, "localhost:6379", 1, 3, errors.New("test")) }},
343376
{"ConnectionNotMarkedForHandoff", func() string { return ConnectionNotMarkedForHandoff(1) }},
344377
{"HandoffRetryAttempt", func() string { return HandoffRetryAttempt(1, 2, "new", "old") }},
345378
{"CannotQueueHandoffForRetry", func() string { return CannotQueueHandoffForRetry(errors.New("test")) }},

logging/logging_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import "testing"
44

55
func TestLogLevel_String(t *testing.T) {
66
tests := []struct {
7-
level LogLevel
7+
level LogLevelT
88
expected string
99
}{
1010
{LogLevelError, "ERROR"},
1111
{LogLevelWarn, "WARN"},
1212
{LogLevelInfo, "INFO"},
1313
{LogLevelDebug, "DEBUG"},
14-
{LogLevel(99), "UNKNOWN"},
14+
{LogLevelT(99), "UNKNOWN"},
1515
}
1616

1717
for _, test := range tests {
@@ -23,16 +23,16 @@ func TestLogLevel_String(t *testing.T) {
2323

2424
func TestLogLevel_IsValid(t *testing.T) {
2525
tests := []struct {
26-
level LogLevel
26+
level LogLevelT
2727
expected bool
2828
}{
2929
{LogLevelError, true},
3030
{LogLevelWarn, true},
3131
{LogLevelInfo, true},
3232
{LogLevelDebug, true},
33-
{LogLevel(-1), false},
34-
{LogLevel(4), false},
35-
{LogLevel(99), false},
33+
{LogLevelT(-1), false},
34+
{LogLevelT(4), false},
35+
{LogLevelT(99), false},
3636
}
3737

3838
for _, test := range tests {

maintnotifications/circuit_breaker_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import (
44
"errors"
55
"testing"
66
"time"
7-
8-
"github.com/redis/go-redis/v9/logging"
97
)
108

119
func TestCircuitBreaker(t *testing.T) {
1210
config := &Config{
13-
LogLevel: logging.LogLevelError, // Reduce noise in tests
1411
CircuitBreakerFailureThreshold: 5,
1512
CircuitBreakerResetTimeout: 60 * time.Second,
1613
CircuitBreakerMaxRequests: 3,
@@ -96,7 +93,6 @@ func TestCircuitBreaker(t *testing.T) {
9693

9794
t.Run("HalfOpenTransition", func(t *testing.T) {
9895
testConfig := &Config{
99-
LogLevel: logging.LogLevelError,
10096
CircuitBreakerFailureThreshold: 5,
10197
CircuitBreakerResetTimeout: 100 * time.Millisecond, // Short timeout for testing
10298
CircuitBreakerMaxRequests: 3,
@@ -134,7 +130,6 @@ func TestCircuitBreaker(t *testing.T) {
134130

135131
t.Run("HalfOpenToClosedTransition", func(t *testing.T) {
136132
testConfig := &Config{
137-
LogLevel: logging.LogLevelError,
138133
CircuitBreakerFailureThreshold: 5,
139134
CircuitBreakerResetTimeout: 50 * time.Millisecond,
140135
CircuitBreakerMaxRequests: 3,
@@ -168,7 +163,6 @@ func TestCircuitBreaker(t *testing.T) {
168163

169164
t.Run("HalfOpenToOpenOnFailure", func(t *testing.T) {
170165
testConfig := &Config{
171-
LogLevel: logging.LogLevelError,
172166
CircuitBreakerFailureThreshold: 5,
173167
CircuitBreakerResetTimeout: 50 * time.Millisecond,
174168
CircuitBreakerMaxRequests: 3,
@@ -233,7 +227,6 @@ func TestCircuitBreaker(t *testing.T) {
233227

234228
func TestCircuitBreakerManager(t *testing.T) {
235229
config := &Config{
236-
LogLevel: logging.LogLevelError,
237230
CircuitBreakerFailureThreshold: 5,
238231
CircuitBreakerResetTimeout: 60 * time.Second,
239232
CircuitBreakerMaxRequests: 3,
@@ -312,7 +305,6 @@ func TestCircuitBreakerManager(t *testing.T) {
312305

313306
t.Run("ConfigurableParameters", func(t *testing.T) {
314307
config := &Config{
315-
LogLevel: logging.LogLevelError,
316308
CircuitBreakerFailureThreshold: 10,
317309
CircuitBreakerResetTimeout: 30 * time.Second,
318310
CircuitBreakerMaxRequests: 5,

maintnotifications/config_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/redis/go-redis/v9/internal/util"
10-
"github.com/redis/go-redis/v9/logging"
1110
)
1211

1312
func TestConfig(t *testing.T) {
@@ -73,7 +72,6 @@ func TestConfig(t *testing.T) {
7372
MaxWorkers: -1, // This should be invalid
7473
HandoffQueueSize: 100,
7574
PostHandoffRelaxedDuration: 10 * time.Second,
76-
LogLevel: 1,
7775
MaxHandoffRetries: 3, // Add required field
7876
}
7977
if err := config.Validate(); err != ErrInvalidHandoffWorkers {
@@ -213,7 +211,6 @@ func TestApplyDefaults(t *testing.T) {
213211
MaxWorkers: 0, // Zero value should get auto-calculated defaults
214212
HandoffQueueSize: 0, // Zero value should get default
215213
RelaxedTimeout: 0, // Zero value should get default
216-
LogLevel: 0, // Zero is valid for LogLevel (errors only)
217214
}
218215

219216
result := config.ApplyDefaultsWithPoolSize(100) // Use explicit pool size for testing
@@ -238,10 +235,7 @@ func TestApplyDefaults(t *testing.T) {
238235
t.Errorf("Expected RelaxedTimeout to be 10s (default), got %v", result.RelaxedTimeout)
239236
}
240237

241-
// LogLevel 0 should be preserved (it's a valid value)
242-
if result.LogLevel != 0 {
243-
t.Errorf("Expected LogLevel to be 0 (preserved), got %d", result.LogLevel)
244-
}
238+
245239
})
246240
}
247241

@@ -305,8 +299,7 @@ func TestIntegrationWithApplyDefaults(t *testing.T) {
305299
t.Run("ProcessorWithPartialConfigAppliesDefaults", func(t *testing.T) {
306300
// Create a partial config with only some fields set
307301
partialConfig := &Config{
308-
MaxWorkers: 15, // Custom value (>= 10 to test preservation)
309-
LogLevel: logging.LogLevelInfo, // Custom value
302+
MaxWorkers: 15, // Custom value (>= 10 to test preservation)
310303
// Other fields left as zero values - should get defaults
311304
}
312305

@@ -332,9 +325,7 @@ func TestIntegrationWithApplyDefaults(t *testing.T) {
332325
t.Errorf("Expected MaxWorkers to be 50, got %d", expectedConfig.MaxWorkers)
333326
}
334327

335-
if expectedConfig.LogLevel != 2 {
336-
t.Errorf("Expected LogLevel to be 2, got %d", expectedConfig.LogLevel)
337-
}
328+
338329

339330
// Should apply defaults for missing fields (auto-calculated queue size with hybrid scaling)
340331
workerBasedSize := expectedConfig.MaxWorkers * 20

0 commit comments

Comments
 (0)