222twotwotwo commented on code in PR #140:
URL: https://github.com/apache/dubbo-getty/pull/140#discussion_r3743705793


##########
client_test.go:
##########
@@ -201,6 +201,71 @@ func TestTCPClient(t *testing.T) {
        assert.True(t, clt.IsClosed())
 }
 
+func TestTCPClientReconnectStopsAfterMaxAttempts(t *testing.T) {
+       listener, err := net.Listen("tcp", "127.0.0.1:0")
+       assert.Nil(t, err)
+       assert.NotNil(t, listener)
+       addr := listener.Addr().String()
+       assert.Nil(t, listener.Close())
+
+       clt := NewTCPClient(
+               WithServerAddress(addr),
+               WithReconnectInterval(int(time.Millisecond)),
+               WithConnectionNumber(1),
+               WithReconnectAttempts(2),
+       )
+       assert.NotNil(t, clt)
+
+       done := make(chan struct{})
+       go func() {
+               var msgHandler MessageHandler
+               cb := func(session Session) error {
+                       return newSessionCallback(session, &msgHandler)
+               }
+               clt.RunEventLoop(cb)
+               close(done)
+       }()
+
+       select {
+       case <-done:
+       case <-time.After(2 * time.Second):
+               t.Fatal("client reconnect loop did not stop after max reconnect 
attempts")
+       }
+
+       clt.Close()
+       assert.True(t, clt.IsClosed())
+}
+
+func TestTCPClientReconnectAttemptsIgnoreSuccessfulPoolFills(t *testing.T) {
+       listener, err := net.Listen("tcp", "127.0.0.1:0")
+       assert.Nil(t, err)
+       assert.NotNil(t, listener)
+       defer func() {
+               _ = listener.Close()
+       }()
+       go func() {
+               _ = http.Serve(listener, nil)
+       }()
+
+       const connPoolSize = 3
+       clt := NewTCPClient(
+               WithServerAddress(listener.Addr().String()),
+               WithReconnectInterval(int(time.Millisecond)),
+               WithConnectionNumber(connPoolSize),
+               WithReconnectAttempts(1),
+       )
+       assert.NotNil(t, clt)
+       defer clt.Close()
+
+       var msgHandler MessageHandler
+       cb := func(session Session) error {
+               return newSessionCallback(session, &msgHandler)
+       }
+       clt.RunEventLoop(cb)
+
+       assert.Equal(t, connPoolSize, msgHandler.SessionNumber())

Review Comment:
   收到,已进行改动



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to