@@ -111,7 +111,9 @@ func TestRedisConnectionProcessor(t *testing.T) {
111111 defer processor .Shutdown (context .Background ())
112112
113113 conn := createMockPoolConnection ()
114- conn .MarkForHandoff ("new-endpoint:6379" , 12345 )
114+ if err := conn .MarkForHandoff ("new-endpoint:6379" , 12345 ); err != nil {
115+ t .Fatalf ("Failed to mark connection for handoff: %v" , err )
116+ }
115117
116118 // Set a mock initialization function
117119 initConnCalled := false
@@ -182,7 +184,9 @@ func TestRedisConnectionProcessor(t *testing.T) {
182184 t .Run ("EmptyEndpoint" , func (t * testing.T ) {
183185 processor := NewRedisConnectionProcessor (3 , baseDialer , nil , nil )
184186 conn := createMockPoolConnection ()
185- conn .MarkForHandoff ("" , 12345 ) // Empty endpoint
187+ if err := conn .MarkForHandoff ("" , 12345 ); err != nil { // Empty endpoint
188+ t .Fatalf ("Failed to mark connection for handoff: %v" , err )
189+ }
186190
187191 ctx := context .Background ()
188192 shouldPool , shouldRemove , err := processor .ProcessConnectionOnPut (ctx , conn )
@@ -214,7 +218,9 @@ func TestRedisConnectionProcessor(t *testing.T) {
214218 defer processor .Shutdown (context .Background ())
215219
216220 conn := createMockPoolConnection ()
217- conn .MarkForHandoff ("new-endpoint:6379" , 12345 )
221+ if err := conn .MarkForHandoff ("new-endpoint:6379" , 12345 ); err != nil {
222+ t .Fatalf ("Failed to mark connection for handoff: %v" , err )
223+ }
218224
219225 ctx := context .Background ()
220226 shouldPool , shouldRemove , err := processor .ProcessConnectionOnPut (ctx , conn )
@@ -359,7 +365,9 @@ func TestRedisConnectionProcessor(t *testing.T) {
359365 connections := make ([]* pool.Conn , 5 )
360366 for i := 0 ; i < 5 ; i ++ {
361367 connections [i ] = createMockPoolConnection ()
362- connections [i ].MarkForHandoff ("new-endpoint:6379" , int64 (i ))
368+ if err := connections [i ].MarkForHandoff ("new-endpoint:6379" , int64 (i )); err != nil {
369+ t .Fatalf ("Failed to mark connection %d for handoff: %v" , i , err )
370+ }
363371 }
364372
365373 ctx := context .Background ()
@@ -438,7 +446,9 @@ func TestRedisConnectionProcessor(t *testing.T) {
438446
439447 // Create a connection and trigger handoff
440448 conn := createMockPoolConnection ()
441- conn .MarkForHandoff ("new-endpoint:6379" , 1 )
449+ if err := conn .MarkForHandoff ("new-endpoint:6379" , 1 ); err != nil {
450+ t .Fatalf ("Failed to mark connection for handoff: %v" , err )
451+ }
442452
443453 // Process the connection to trigger handoff
444454 shouldPool , shouldRemove , err := processor .ProcessConnectionOnPut (ctx , conn )
@@ -516,7 +526,9 @@ func TestRedisConnectionProcessor(t *testing.T) {
516526 }
517527
518528 // Mark connection for handoff
519- conn .MarkForHandoff ("new-endpoint:6379" , 1 )
529+ if err := conn .MarkForHandoff ("new-endpoint:6379" , 1 ); err != nil {
530+ t .Fatalf ("Failed to mark connection for handoff: %v" , err )
531+ }
520532
521533 // Connection should no longer be usable
522534 if conn .IsUsable () {
@@ -583,7 +595,9 @@ func TestRedisConnectionProcessor(t *testing.T) {
583595 // Fill part of the queue
584596 for i := 0 ; i < 10 ; i ++ {
585597 conn := createMockPoolConnection ()
586- conn .MarkForHandoff ("new-endpoint:6379" , int64 (i + 1 ))
598+ if err := conn .MarkForHandoff ("new-endpoint:6379" , int64 (i + 1 )); err != nil {
599+ t .Fatalf ("Failed to mark connection %d for handoff: %v" , i , err )
600+ }
587601
588602 shouldPool , shouldRemove , err := processor .ProcessConnectionOnPut (ctx , conn )
589603 if err != nil {
@@ -634,7 +648,9 @@ func TestRedisConnectionProcessor(t *testing.T) {
634648
635649 // Create a connection and mark it for handoff
636650 conn := createMockPoolConnection ()
637- conn .MarkForHandoff ("new-endpoint:6379" , 1 )
651+ if err := conn .MarkForHandoff ("new-endpoint:6379" , 1 ); err != nil {
652+ t .Fatalf ("Failed to mark connection for handoff: %v" , err )
653+ }
638654
639655 // Set a failing initialization function
640656 conn .SetInitConnFunc (func (ctx context.Context , cn * pool.Conn ) error {
@@ -712,4 +728,31 @@ func TestRedisConnectionProcessor(t *testing.T) {
712728 t .Error ("Relaxed timeout should be automatically cleared after post-handoff duration" )
713729 }
714730 })
731+
732+ t .Run ("MarkForHandoff returns error when already marked" , func (t * testing.T ) {
733+ conn := createMockPoolConnection ()
734+
735+ // First mark should succeed
736+ if err := conn .MarkForHandoff ("new-endpoint:6379" , 1 ); err != nil {
737+ t .Fatalf ("First MarkForHandoff should succeed: %v" , err )
738+ }
739+
740+ // Second mark should fail
741+ if err := conn .MarkForHandoff ("another-endpoint:6379" , 2 ); err == nil {
742+ t .Fatal ("Second MarkForHandoff should return error" )
743+ } else if err .Error () != "connection is already marked for handoff" {
744+ t .Fatalf ("Expected specific error message, got: %v" , err )
745+ }
746+
747+ // Verify original handoff data is preserved
748+ if ! conn .ShouldHandoff () {
749+ t .Fatal ("Connection should still be marked for handoff" )
750+ }
751+ if conn .GetHandoffEndpoint () != "new-endpoint:6379" {
752+ t .Fatalf ("Expected original endpoint, got: %s" , conn .GetHandoffEndpoint ())
753+ }
754+ if conn .GetMovingSeqID () != 1 {
755+ t .Fatalf ("Expected original sequence ID, got: %d" , conn .GetMovingSeqID ())
756+ }
757+ })
715758}
0 commit comments