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

Function TestEventDrivenHandoffIntegration

async_handoff_integration_test.go:38–398  ·  async_handoff_integration_test.go::TestEventDrivenHandoffIntegration

TestEventDrivenHandoffIntegration tests the complete event-driven handoff flow

(t *testing.T)

Source from the content-addressed store, hash-verified

36
37// TestEventDrivenHandoffIntegration tests the complete event-driven handoff flow
38func TestEventDrivenHandoffIntegration(t *testing.T) {
39 t.Run("EventDrivenHandoffWithPoolSkipping", func(t *testing.T) {
40 // Create a base dialer for testing
41 baseDialer := func(ctx context.Context, network, addr string) (net.Conn, error) {
42 return &mockNetConn{addr: addr}, nil
43 }
44
45 // Create processor with event-driven handoff support
46 processor := maintnotifications.NewPoolHook(baseDialer, "tcp", nil, nil)
47 defer processor.Shutdown(context.Background())
48
49 // Reset circuit breakers to ensure clean state for this test
50 processor.ResetCircuitBreakers()
51
52 // Create a test pool with hooks
53 hookManager := pool.NewPoolHookManager()
54 hookManager.AddHook(processor)
55
56 testPool := pool.NewConnPool(&pool.Options{
57 Dialer: func(ctx context.Context) (net.Conn, error) {
58 return &mockNetConn{addr: "original:6379"}, nil
59 },
60 PoolSize: int32(5),
61 MaxConcurrentDials: 5,
62 PoolTimeout: time.Second,
63 })
64
65 // Add the hook to the pool after creation
66 testPool.AddPoolHook(processor)
67 defer testPool.Close()
68
69 // Set the pool reference in the processor for connection removal on handoff failure
70 processor.SetPool(testPool)
71
72 ctx := context.Background()
73
74 // Get a connection and mark it for handoff
75 conn, err := testPool.Get(ctx)
76 if err != nil {
77 t.Fatalf("Failed to get connection: %v", err)
78 }
79
80 // Set initialization function with a small delay to ensure handoff is pending
81 var initConnCalled atomic.Bool
82 initConnStarted := make(chan struct{})
83 initConnFunc := func(ctx context.Context, cn *pool.Conn) error {
84 close(initConnStarted) // Signal that InitConn has started
85 time.Sleep(50 * time.Millisecond) // Add delay to keep handoff pending
86 initConnCalled.Store(true)
87 return nil
88 }
89 conn.SetInitConnFunc(initConnFunc)
90
91 // Mark connection for handoff
92 err = conn.MarkForHandoff("new-endpoint:6379", 12345)
93 if err != nil {
94 t.Fatalf("Failed to mark connection for handoff: %v", err)
95 }

Callers

nothing calls this directly

Calls 15

ShutdownMethod · 0.95
ResetCircuitBreakersMethod · 0.95
AddHookMethod · 0.95
AddPoolHookMethod · 0.95
CloseMethod · 0.95
SetPoolMethod · 0.95
GetMethod · 0.95
PutMethod · 0.95
IsHandoffPendingMethod · 0.95
NewPoolHookFunction · 0.92
NewPoolHookManagerFunction · 0.92
NewConnPoolFunction · 0.92

Tested by

no test coverage detected