MCPcopy
hub / github.com/redis/go-redis / TestManagerRefactoring

Function TestManagerRefactoring

maintnotifications/manager_test.go:152–337  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

150}
151
152func TestManagerRefactoring(t *testing.T) {
153 t.Run("AtomicStateTracking", func(t *testing.T) {
154 config := DefaultConfig()
155 client := &MockClient{options: &MockOptions{}}
156
157 manager, err := NewManager(client, nil, config)
158 if err != nil {
159 t.Fatalf("Failed to create maintnotifications manager: %v", err)
160 }
161 defer manager.Close()
162
163 // Test initial state
164 if manager.IsHandoffInProgress() {
165 t.Error("Expected no handoff in progress initially")
166 }
167
168 if manager.GetActiveOperationCount() != 0 {
169 t.Errorf("Expected 0 active operations, got %d", manager.GetActiveOperationCount())
170 }
171
172 if manager.GetState() != StateIdle {
173 t.Errorf("Expected StateIdle, got %v", manager.GetState())
174 }
175
176 // Add an operation
177 ctx := context.Background()
178 deadline := time.Now().Add(30 * time.Second)
179 err = manager.TrackMovingOperationWithConnID(ctx, "new-endpoint:6379", deadline, 12345, 1)
180 if err != nil {
181 t.Fatalf("Failed to track operation: %v", err)
182 }
183
184 // Test state after adding operation
185 if !manager.IsHandoffInProgress() {
186 t.Error("Expected handoff in progress after adding operation")
187 }
188
189 if manager.GetActiveOperationCount() != 1 {
190 t.Errorf("Expected 1 active operation, got %d", manager.GetActiveOperationCount())
191 }
192
193 if manager.GetState() != StateMoving {
194 t.Errorf("Expected StateMoving, got %v", manager.GetState())
195 }
196
197 // Remove the operation
198 manager.UntrackOperationWithConnID(12345, 1)
199
200 // Test state after removing operation
201 if manager.IsHandoffInProgress() {
202 t.Error("Expected no handoff in progress after removing operation")
203 }
204
205 if manager.GetActiveOperationCount() != 0 {
206 t.Errorf("Expected 0 active operations, got %d", manager.GetActiveOperationCount())
207 }
208
209 if manager.GetState() != StateIdle {

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
IsHandoffInProgressMethod · 0.95
GetStateMethod · 0.95
DefaultConfigFunction · 0.85
NewManagerFunction · 0.70
AddMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected