AlexStocks commented on code in PR #3599:
URL: https://github.com/apache/dubbo-go/pull/3599#discussion_r3733604571
##########
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:
[P1] 补上连接 ready 后、发布前 Close 的回归测试
当前测试只在 newGettyRPCClientConn 仍等待连接时关闭 client,没有经过 getOrCreateGettyClient
创建完成后的两次 closed 门禁。我在 exact Head mutant 中删除这两个检查后,4 个新增关闭测试以 -race -count=20
仍全部通过;该实现可在 Close 已消费 closeOnce 后再发布连接,连接将无法被后续 Close 回收。建议通过可控 connection
factory/同步点把创建暂停在 ready 与 publish 之间,先完成 Close,再断言创建返回
errClientClosed、未发布连接被关闭且 c.gettyClient 仍为 nil。
--
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]