@@ -86,16 +86,6 @@ func mockDialer(ctx context.Context, network, addr string) (net.Conn, error) {
8686 return c , ctx .Err ()
8787}
8888
89- // mockDialer mocks the net.Dial interface by returning a mock connection to
90- // the given address.
91- func mockDialerAddr (ctx context.Context , addr net.Addr ) (net.Conn , error ) {
92- r , w := io .Pipe ()
93- c := & mockConn {rAddr : addr }
94- c .Reader = r
95- c .Writer = w
96- return c , nil
97- }
98-
9989// TestNewConfig tests that new ConnManager config is validated as expected.
10090func TestNewConfig (t * testing.T ) {
10191 _ , err := New (& Config {})
@@ -108,21 +98,6 @@ func TestNewConfig(t *testing.T) {
10898 if err != nil {
10999 t .Fatalf ("New unexpected error: %v" , err )
110100 }
111-
112- _ , err = New (& Config {
113- Dial : mockDialer ,
114- DialAddr : mockDialerAddr ,
115- })
116- if err == nil {
117- t .Fatal ("New expected error: 'Dial and DialAddr can't be both nil', got nil" )
118- }
119-
120- _ , err = New (& Config {
121- DialAddr : mockDialerAddr ,
122- })
123- if err != nil {
124- t .Fatalf ("New unexpected error: %v" , err )
125- }
126101}
127102
128103// assertConnReqID ensures the provided connection request has the given ID.
@@ -247,54 +222,6 @@ func TestTargetOutbound(t *testing.T) {
247222 wg .Wait ()
248223}
249224
250- // TestPassAddrAlongDialAddr tests if when using the DialAddr config option,
251- // any address object returned by GetNewAddress will be correctly passed along
252- // to DialAddr to be used for connecting to a host.
253- func TestPassAddrAlongDialAddr (t * testing.T ) {
254- dailedAddr := make (chan net.Addr )
255- detectDialer := func (ctx context.Context , addr net.Addr ) (net.Conn , error ) {
256- dailedAddr <- addr
257- return nil , errors .New ("error" )
258- }
259-
260- // targetAddr will be the specific address we'll use to connect. It _could_
261- // be carrying more info than a standard (tcp/udp) network address, so it
262- // needs to be relayed to dialAddr.
263- targetAddr := mockAddr {
264- net : "invalid" ,
265- address : "unreachable" ,
266- }
267-
268- cmgr , err := New (& Config {
269- TargetOutbound : 1 ,
270- DialAddr : detectDialer ,
271- GetNewAddress : func () (net.Addr , error ) {
272- return targetAddr , nil
273- },
274- })
275- if err != nil {
276- t .Fatalf ("New error: %v" , err )
277- }
278- _ , shutdown , wg := runConnMgrAsync (context .Background (), cmgr )
279-
280- select {
281- case addr := <- dailedAddr :
282- receivedMock , isMockAddr := addr .(mockAddr )
283- if ! isMockAddr {
284- t .Fatal ("connected to an address that was not a mockAddr" )
285- }
286- if receivedMock != targetAddr {
287- t .Fatal ("connected to an address different than the expected target" )
288- }
289- case <- time .After (time .Millisecond * 20 ):
290- t .Fatal ("did not get connection to target address before timeout" )
291- }
292-
293- // Ensure clean shutdown of connection manager.
294- shutdown ()
295- wg .Wait ()
296- }
297-
298225// TestRetryPermanent tests that permanent connection requests are retried.
299226//
300227// We make a permanent connection request using Connect, disconnect it using
@@ -588,13 +515,13 @@ func TestRemovePendingConnection(t *testing.T) {
588515 // succeed.
589516 dialed := make (chan struct {})
590517 wait := make (chan struct {})
591- indefiniteDialer := func (ctx context.Context , addr net. Addr ) (net.Conn , error ) {
518+ indefiniteDialer := func (ctx context.Context , network , addr string ) (net.Conn , error ) {
592519 close (dialed )
593520 <- wait
594521 return nil , errors .New ("error" )
595522 }
596523 cmgr , err := New (& Config {
597- DialAddr : indefiniteDialer ,
524+ Dial : indefiniteDialer ,
598525 })
599526 if err != nil {
600527 t .Fatalf ("New error: %v" , err )
@@ -646,10 +573,10 @@ func TestCancelIgnoreDelayedConnection(t *testing.T) {
646573 // connect chan is signaled. The dial attempt immediately after that
647574 // will succeed in returning a connection.
648575 connect := make (chan struct {})
649- failingDialer := func (ctx context.Context , addr net. Addr ) (net.Conn , error ) {
576+ failingDialer := func (ctx context.Context , network , addr string ) (net.Conn , error ) {
650577 select {
651578 case <- connect :
652- return mockDialerAddr (ctx , addr )
579+ return mockDialer (ctx , network , addr )
653580 default :
654581 }
655582
@@ -658,7 +585,7 @@ func TestCancelIgnoreDelayedConnection(t *testing.T) {
658585
659586 connected := make (chan * ConnReq )
660587 cmgr , err := New (& Config {
661- DialAddr : failingDialer ,
588+ Dial : failingDialer ,
662589 RetryDuration : retryTimeout ,
663590 OnConnection : func (c * ConnReq , conn net.Conn ) {
664591 connected <- c
@@ -822,17 +749,17 @@ func TestForEachConnReq(t *testing.T) {
822749 targetOutbound := uint32 (5 )
823750 connected := make (chan * ConnReq )
824751 pending := make (chan struct {})
825- delayDialer := func (ctx context.Context , addr net. Addr ) (net.Conn , error ) {
826- if addr . String () == "127.0.0.1:18557" {
752+ delayDialer := func (ctx context.Context , network , addr string ) (net.Conn , error ) {
753+ if addr == "127.0.0.1:18557" {
827754 close (pending )
828755 time .Sleep (time .Second )
829756 return nil , errors .New ("error" )
830757 }
831- return mockDialerAddr (ctx , addr )
758+ return mockDialer (ctx , network , addr )
832759 }
833760 cmgr , err := New (& Config {
834761 TargetOutbound : targetOutbound ,
835- DialAddr : delayDialer ,
762+ Dial : delayDialer ,
836763 GetNewAddress : func () (net.Addr , error ) {
837764 return & net.TCPAddr {
838765 IP : net .ParseIP ("127.0.0.1" ),
0 commit comments