Skip to content

Commit 919cc6a

Browse files
committed
cleanup and doc
1 parent 63c2290 commit 919cc6a

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

hitless/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *
262262
var queueCap int
263263
if maxActiveConns > 0 {
264264
queueCap = maxActiveConns + 1
265+
// Ensure queue cap is at least 2 for very small maxActiveConns
266+
if queueCap < 2 {
267+
queueCap = 2
268+
}
265269
} else {
266270
queueCap = poolSize * 5
267271
}

hitless/hitless_manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ func (hm *HitlessManager) UntrackOperationWithConnID(seqID int64, connID uint64)
186186
}
187187

188188
// GetActiveMovingOperations returns active operations with composite keys.
189+
// WARNING: This method creates a new map and copies all operations on every call.
190+
// Use sparingly, especially in hot paths or high-frequency logging.
189191
func (hm *HitlessManager) GetActiveMovingOperations() map[MovingOperationKey]*MovingOperation {
190192
result := make(map[MovingOperationKey]*MovingOperation)
191193

hitless/push_notification_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ func (snh *NotificationHandler) handleMoving(ctx context.Context, handlerCtx pus
130130
return
131131
}
132132
if err := snh.markConnForHandoff(poolConn, newEndpoint, seqID, deadline); err != nil {
133-
// Log error but don't fail the goroutine
134-
internal.Logger.Printf(ctx, "hitless: failed to mark connection for handoff: %v", err)
133+
// Log error but don't fail the goroutine - use background context since original may be cancelled
134+
internal.Logger.Printf(context.Background(), "hitless: failed to mark connection for handoff: %v", err)
135135
}
136136
})
137137
return nil

logging/logging.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package logging provides logging level constants and utilities for the go-redis library.
2+
// This package centralizes logging configuration to ensure consistency across all components.
13
package logging
24

35
// LogLevel represents the logging level

logging/logging_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package logging
2+
3+
import "testing"
4+
5+
func TestLogLevel_String(t *testing.T) {
6+
tests := []struct {
7+
level LogLevel
8+
expected string
9+
}{
10+
{LogLevelError, "ERROR"},
11+
{LogLevelWarn, "WARN"},
12+
{LogLevelInfo, "INFO"},
13+
{LogLevelDebug, "DEBUG"},
14+
{LogLevel(99), "UNKNOWN"},
15+
}
16+
17+
for _, test := range tests {
18+
if got := test.level.String(); got != test.expected {
19+
t.Errorf("LogLevel(%d).String() = %q, want %q", test.level, got, test.expected)
20+
}
21+
}
22+
}
23+
24+
func TestLogLevel_IsValid(t *testing.T) {
25+
tests := []struct {
26+
level LogLevel
27+
expected bool
28+
}{
29+
{LogLevelError, true},
30+
{LogLevelWarn, true},
31+
{LogLevelInfo, true},
32+
{LogLevelDebug, true},
33+
{LogLevel(-1), false},
34+
{LogLevel(4), false},
35+
{LogLevel(99), false},
36+
}
37+
38+
for _, test := range tests {
39+
if got := test.level.IsValid(); got != test.expected {
40+
t.Errorf("LogLevel(%d).IsValid() = %v, want %v", test.level, got, test.expected)
41+
}
42+
}
43+
}
44+
45+
func TestLogLevelConstants(t *testing.T) {
46+
// Test that constants have expected values
47+
if LogLevelError != 0 {
48+
t.Errorf("LogLevelError = %d, want 0", LogLevelError)
49+
}
50+
if LogLevelWarn != 1 {
51+
t.Errorf("LogLevelWarn = %d, want 1", LogLevelWarn)
52+
}
53+
if LogLevelInfo != 2 {
54+
t.Errorf("LogLevelInfo = %d, want 2", LogLevelInfo)
55+
}
56+
if LogLevelDebug != 3 {
57+
t.Errorf("LogLevelDebug = %d, want 3", LogLevelDebug)
58+
}
59+
}

0 commit comments

Comments
 (0)