buptubuntu commented on a change in pull request #2497:
URL: https://github.com/apache/thrift/pull/2497#discussion_r792265616



##########
File path: lib/go/thrift/simple_server_test.go
##########
@@ -154,3 +158,112 @@ func 
TestNoHangDuringStopFromDanglingLockAcquireDuringAcceptLoop(t *testing.T) {
        runtime.Gosched()
        serv.Stop()
 }
+
+func TestNoHangDuringStopFromClientNoDataSendDuringAcceptLoop(t *testing.T) {
+       ln, _ := net.Listen("tcp", "localhost:0")
+
+       proc := &mockProcessor{
+               ProcessFunc: func(in, out TProtocol) (bool, TException) {
+                       in.ReadMessageBegin(context.Background())
+                       return false, nil
+               },
+       }
+
+       trans := &mockServerTransport{
+               ListenFunc: func() error {
+                       return nil
+               },
+               AcceptFunc: func() (TTransport, error) {
+                       conn, err := ln.Accept()
+                       if err != nil {
+                               return nil, err
+                       }
+
+                       return NewTSocketFromConnConf(conn, nil), nil
+               },
+               CloseFunc: func() error {
+                       return nil
+               },
+               InterruptFunc: func() error {
+                       return ln.Close()
+               },
+       }
+
+       serv := NewTSimpleServer2(proc, trans)
+       go serv.Serve()
+       time.Sleep(10 * time.Millisecond)
+
+       netConn, err := net.Dial("tcp", ln.Addr().String())
+       if err != nil || netConn == nil {
+               t.Fatal("error when dial server")
+       }
+       time.Sleep(10 * time.Millisecond)
+
+       st := time.Now()
+       ServerCloseTimeout = 50 * time.Millisecond
+       err = serv.Stop()
+       if err != nil {
+               t.Logf("error when stop server:%v", err)
+               t.FailNow()
+       }
+       if time.Since(st) < 50*time.Millisecond {
+               t.Logf("stop cost less time than socket timeout, server close 
timeout:%v,cost time:%v", ServerCloseTimeout, time.Since(st))
+               t.FailNow()
+       }
+}
+
+func TestStopTimeoutWithSocketTimeout(t *testing.T) {
+       ln, _ := net.Listen("tcp", "localhost:0")
+
+       proc := &mockProcessor{
+               ProcessFunc: func(in, out TProtocol) (bool, TException) {
+                       in.ReadMessageBegin(context.Background())
+                       return false, nil
+               },
+       }
+
+       conf := &TConfiguration{SocketTimeout: 5 * time.Millisecond}
+       wg := &sync.WaitGroup{}
+       trans := &mockServerTransport{
+               ListenFunc: func() error {
+                       return nil
+               },
+               AcceptFunc: func() (TTransport, error) {
+                       conn, err := ln.Accept()
+                       if err != nil {
+                               return nil, err
+                       }
+                       defer wg.Done()
+                       return NewTSocketFromConnConf(conn, conf), nil
+               },
+               CloseFunc: func() error {
+                       return nil
+               },
+               InterruptFunc: func() error {
+                       return ln.Close()
+               },
+       }
+
+       serv := NewTSimpleServer2(proc, trans)
+       go serv.Serve()
+       time.Sleep(10 * time.Millisecond)
+
+       wg.Add(1)
+       netConn, err := net.Dial("tcp", ln.Addr().String())
+       if err != nil || netConn == nil {
+               t.Fatal("error when dial server")
+       }
+       wg.Wait()
+
+       st := time.Now()
+       ServerCloseTimeout = 50 * time.Millisecond
+       err = serv.Stop()
+       if time.Since(st) >= 10*time.Millisecond {

Review comment:
       Yes, I actually use time.Since(st) >= 6*time.Millisecond before and the 
test result is not stable




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


Reply via email to