@@ -152,9 +152,20 @@ func TestForwardProxy(t *testing.T) {
152152 opts = append (opts , WithProxy (fp ))
153153
154154 svcInfo := mocks .ServiceInfo ()
155+ // Configure long pool and check if the pool is closed when initProxy
156+ // If the proxy does not configure pool, use the predefined pool
157+ mockLongPool := mock_remote .NewMockLongConnPool (ctrl )
158+ var closed bool
159+ mockLongPool .EXPECT ().Get (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (mocksnetpoll .NewMockConnection (ctrl ), nil ).Times (1 )
160+ mockLongPool .EXPECT ().Close ().Do (func () {
161+ closed = true
162+ }).AnyTimes ()
163+ mockLongPool .EXPECT ().Put (gomock .Any ()).Return (nil ).AnyTimes ()
164+ mockLongPool .EXPECT ().Discard (gomock .Any ()).Return (nil ).AnyTimes ()
165+ opts = append (opts , WithConnPool (mockLongPool ))
155166 cli , err := NewClient (svcInfo , opts ... )
156167 test .Assert (t , err == nil )
157-
168+ test . Assert ( t , ! closed )
158169 mtd := mocks .MockMethod
159170 ctx := context .Background ()
160171 req := new (MockTStruct )
@@ -328,13 +339,23 @@ func TestProxyWithConnPool(t *testing.T) {
328339 opts = append (opts , WithTransHandlerFactory (newMockCliTransHandlerFactory (ctrl )))
329340 opts = append (opts , WithDestService ("destService" ))
330341 opts = append (opts , WithProxy (fp ))
331- opts = append (opts , WithConnPool (& mockLongConnPool {mock_remote .NewMockLongConnPool (ctrl ), mock_remote .NewMockConnPoolReporter (ctrl )}))
332342 opts = append (opts , WithConnReporterEnabled ())
333343 opts = append (opts , WithResolver (resolver404 (ctrl )))
344+ // Preconfigured longConnPool should be closed because the proxy configured the pool
345+ mockLongPool := mock_remote .NewMockLongConnPool (ctrl )
346+ var closed bool
347+ mockLongPool .EXPECT ().Get (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (mocksnetpoll .NewMockConnection (ctrl ), nil ).Times (0 )
348+ mockLongPool .EXPECT ().Close ().Do (func () {
349+ closed = true
350+ }).AnyTimes ()
351+ mockLongPool .EXPECT ().Put (gomock .Any ()).Return (nil ).AnyTimes ()
352+ mockLongPool .EXPECT ().Discard (gomock .Any ()).Return (nil ).AnyTimes ()
353+ opts = append (opts , WithConnPool (mockLongPool ))
334354
335355 svcInfo := mocks .ServiceInfo ()
336356 cli , err := NewClient (svcInfo , opts ... )
337357 test .Assert (t , err == nil )
358+ test .Assert (t , closed ) // should be true
338359
339360 mtd := mocks .MockMethod
340361 ctx := context .Background ()
@@ -556,10 +577,41 @@ func TestWithBoundHandler(t *testing.T) {
556577 ctrl := gomock .NewController (t )
557578 defer ctrl .Finish ()
558579
580+ mockInboundHandler := mock_remote .NewMockInboundHandler (ctrl )
581+ opts := client .NewOptions ([]client.Option {WithBoundHandler (mockInboundHandler )})
582+ test .Assert (t , len (opts .RemoteOpt .Outbounds ) == 0 )
583+ test .Assert (t , len (opts .RemoteOpt .Inbounds ) == 1 )
584+
585+ opts = client .NewOptions ([]client.Option {WithBoundHandler (mockInboundHandler ), WithBoundHandler (mockInboundHandler )})
586+ test .Assert (t , len (opts .RemoteOpt .Outbounds ) == 0 )
587+ test .Assert (t , len (opts .RemoteOpt .Inbounds ) == 1 )
588+
589+ mockInboundHandler2 := mock_remote .NewMockInboundHandler (ctrl )
590+ opts = client .NewOptions ([]client.Option {WithBoundHandler (mockInboundHandler ), WithBoundHandler (mockInboundHandler2 )})
591+ test .Assert (t , len (opts .RemoteOpt .Outbounds ) == 0 )
592+ test .Assert (t , len (opts .RemoteOpt .Inbounds ) == 1 )
593+
559594 mockOutboundHandler := mock_remote .NewMockOutboundHandler (ctrl )
560- opts : = client .NewOptions ([]client.Option {WithBoundHandler (mockOutboundHandler )})
561- test .Assert (t , len (opts .RemoteOpt .Outbounds ) > 0 )
595+ opts = client .NewOptions ([]client.Option {WithBoundHandler (mockOutboundHandler )})
596+ test .Assert (t , len (opts .RemoteOpt .Outbounds ) == 1 )
562597 test .Assert (t , len (opts .RemoteOpt .Inbounds ) == 0 )
598+
599+ opts = client .NewOptions (
600+ []client.Option {WithBoundHandler (mockOutboundHandler ), WithBoundHandler (mockOutboundHandler )})
601+ test .Assert (t , len (opts .RemoteOpt .Outbounds ) == 1 )
602+ test .Assert (t , len (opts .RemoteOpt .Inbounds ) == 0 )
603+
604+ mockOutboundHandler2 := mock_remote .NewMockOutboundHandler (ctrl )
605+ opts = client .NewOptions ([]client.Option {
606+ WithBoundHandler (mockOutboundHandler ), WithBoundHandler (mockOutboundHandler2 ),
607+ })
608+ test .Assert (t , len (opts .RemoteOpt .Outbounds ) == 1 )
609+ test .Assert (t , len (opts .RemoteOpt .Inbounds ) == 0 )
610+
611+ mockDuplexBoundHandler := mock_remote .NewMockDuplexBoundHandler (ctrl )
612+ opts = client .NewOptions ([]client.Option {WithBoundHandler (mockDuplexBoundHandler ), WithBoundHandler (mockDuplexBoundHandler )})
613+ test .Assert (t , len (opts .RemoteOpt .Outbounds ) == 1 )
614+ test .Assert (t , len (opts .RemoteOpt .Inbounds ) == 1 )
563615}
564616
565617// collection of options
0 commit comments