DadaVinqi commented on code in PR #3599:
URL: https://github.com/apache/dubbo-go/pull/3599#discussion_r3733760328


##########
remoting/getty/getty_client_test.go:
##########
@@ -331,3 +332,90 @@ func TestInitClientTLS(t *testing.T) {
                assert.False(t, clientConf.SSLEnabled)
        })
 }
+
+func TestGettyConnectWaitStopsWhenClosed(t *testing.T) {
+       client := NewClient(Options{ConnectTimeout: 5 * time.Second})
+       started := make(chan struct{})
+       var startOnce sync.Once
+       available := func() bool {
+               startOnce.Do(func() { close(started) })
+               return false
+       }
+       waitDone := make(chan error, 1)
+       go func() {
+               waitDone <- waitForGettyClient("127.0.0.1:1", 
client.opts.ConnectTimeout, available, client.done)
+       }()
+       select {
+       case <-started:
+       case <-time.After(time.Second):
+               t.Fatal("connection wait did not start")
+       }
+
+       start := time.Now()
+       client.Close()
+       err := <-waitDone
+
+       require.Error(t, err)
+       require.ErrorIs(t, err, errClientClosed)
+       require.Less(t, time.Since(start), time.Second)
+}
+
+func TestGettyConnectWaitHonorsTimeout(t *testing.T) {
+       start := time.Now()
+       err := waitForGettyClient("127.0.0.1:1", 30*time.Millisecond,
+               func() bool { return false },
+               nil,
+       )
+
+       require.Error(t, err)
+       require.NotErrorIs(t, err, errClientClosed)
+       require.Less(t, time.Since(start), time.Second)
+}
+
+func TestGettyNewConnectionStopsWhenClientCloses(t *testing.T) {

Review Comment:
   做了修改:新增 `TestGettyCloseAfterConnectionReadyBeforePublish`,用同步 factory 覆盖连接 
ready 后、发布前执行 `Close()` 的竞态,并断言返回 `errClientClosed`、未发布连接被关闭且共享 `gettyClient` 
保持 nil。同时将连接发布前的关闭检查收敛到 `gettyClientMux` 锁内,避免慢速建连期间持有指针锁。已通过 `go test -race 
-count=20 ./remoting/getty -run 
TestGettyCloseAfterConnectionReadyBeforePublish`、`make test` 和 `make 
lint`。修复提交:`ecac3321`。



-- 
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