Skip to content

Commit 0507340

Browse files
committed
fix
1 parent d79dcec commit 0507340

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

async_handoff_integration_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,28 @@ func TestEventDrivenHandoffIntegration(t *testing.T) {
272272
t.Fatalf("Failed to get connection: %v", err)
273273
}
274274

275-
conn.MarkForHandoff("new-endpoint:6379", 12345)
275+
if err := conn.MarkForHandoff("new-endpoint:6379", 12345); err != nil {
276+
t.Fatalf("Failed to mark connection for handoff: %v", err)
277+
}
278+
279+
// Set a mock initialization function
280+
conn.SetInitConnFunc(func(ctx context.Context, cn *pool.Conn) error {
281+
return nil
282+
})
283+
276284
testPool.Put(ctx, conn)
277285

278286
// Verify handoff was queued
279287
if !processor.IsHandoffPending(conn) {
280288
t.Error("Handoff should be queued in pending map")
281289
}
282290

291+
// Give the handoff a moment to start processing
292+
time.Sleep(50 * time.Millisecond)
293+
283294
// Shutdown processor gracefully
284-
shutdownCtx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
295+
// Use a longer timeout to account for slow dialer (100ms) plus processing overhead
296+
shutdownCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
285297
defer cancel()
286298

287299
err = processor.Shutdown(shutdownCtx)

hitless/redis_connection_processor_test.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ func TestRedisConnectionProcessor(t *testing.T) {
368368
if err := connections[i].MarkForHandoff("new-endpoint:6379", int64(i)); err != nil {
369369
t.Fatalf("Failed to mark connection %d for handoff: %v", i, err)
370370
}
371+
// Set a mock initialization function
372+
connections[i].SetInitConnFunc(func(ctx context.Context, cn *pool.Conn) error {
373+
return nil
374+
})
371375
}
372376

373377
ctx := context.Background()
@@ -450,6 +454,11 @@ func TestRedisConnectionProcessor(t *testing.T) {
450454
t.Fatalf("Failed to mark connection for handoff: %v", err)
451455
}
452456

457+
// Set a mock initialization function
458+
conn.SetInitConnFunc(func(ctx context.Context, cn *pool.Conn) error {
459+
return nil
460+
})
461+
453462
// Process the connection to trigger handoff
454463
shouldPool, shouldRemove, err := processor.ProcessConnectionOnPut(ctx, conn)
455464
if err != nil {
@@ -530,6 +539,11 @@ func TestRedisConnectionProcessor(t *testing.T) {
530539
t.Fatalf("Failed to mark connection for handoff: %v", err)
531540
}
532541

542+
// Set a mock initialization function
543+
conn.SetInitConnFunc(func(ctx context.Context, cn *pool.Conn) error {
544+
return nil
545+
})
546+
533547
// Connection should no longer be usable
534548
if conn.IsUsable() {
535549
t.Error("Connection should not be usable after being marked for handoff")
@@ -598,6 +612,10 @@ func TestRedisConnectionProcessor(t *testing.T) {
598612
if err := conn.MarkForHandoff("new-endpoint:6379", int64(i+1)); err != nil {
599613
t.Fatalf("Failed to mark connection %d for handoff: %v", i, err)
600614
}
615+
// Set a mock initialization function
616+
conn.SetInitConnFunc(func(ctx context.Context, cn *pool.Conn) error {
617+
return nil
618+
})
601619

602620
shouldPool, shouldRemove, err := processor.ProcessConnectionOnPut(ctx, conn)
603621
if err != nil {
@@ -695,7 +713,14 @@ func TestRedisConnectionProcessor(t *testing.T) {
695713
defer processor.Shutdown(context.Background())
696714

697715
conn := createMockPoolConnection()
698-
conn.MarkForHandoff("new-endpoint:6379", 12345)
716+
if err := conn.MarkForHandoff("new-endpoint:6379", 12345); err != nil {
717+
t.Fatalf("Failed to mark connection for handoff: %v", err)
718+
}
719+
720+
// Set a mock initialization function
721+
conn.SetInitConnFunc(func(ctx context.Context, cn *pool.Conn) error {
722+
return nil
723+
})
699724

700725
ctx := context.Background()
701726
shouldPool, shouldRemove, err := processor.ProcessConnectionOnPut(ctx, conn)

internal/pool/conn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func (cn *Conn) ExecuteInitConn(ctx context.Context) error {
323323
}
324324
cn.Inited = true
325325
cn.setUsable(true) // Use atomic operation
326+
return nil
326327
}
327328
return fmt.Errorf("redis: no initConnFunc set for connection %d", cn.GetID())
328329
}

0 commit comments

Comments
 (0)