fix data race issue in unit testing of gtcp

This commit is contained in:
John 2019-12-13 13:43:28 +08:00
parent f4e8fbe767
commit 2d754f80b1
4 changed files with 9 additions and 5 deletions

View File

@ -52,7 +52,7 @@ func NewServer(address string, handler func(*Conn), name ...string) *Server {
address: address,
handler: handler,
}
if len(name) > 0 {
if len(name) > 0 && name[0] != "" {
serverMapping.Set(name[0], s)
}
return s

View File

@ -27,7 +27,9 @@ func Test_Pool_Basic1(t *testing.T) {
}
})
go s.Run()
defer s.Close()
defer func() {
s.Close()
}()
time.Sleep(100 * time.Millisecond)
gtest.Case(t, func() {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
@ -47,7 +49,9 @@ func Test_Pool_Basic2(t *testing.T) {
conn.Close()
})
go s.Run()
defer s.Close()
defer func() {
s.Close()
}()
time.Sleep(100 * time.Millisecond)
gtest.Case(t, func() {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))

View File

@ -154,7 +154,7 @@ func (c *Conn) Recv(length int, retry ...Retry) ([]byte, error) {
if retry[0].Interval == 0 {
retry[0].Interval = gDEFAULT_RETRY_INTERVAL
}
time.Sleep(time.Duration(retry[0].Interval) * time.Millisecond)
time.Sleep(retry[0].Interval)
continue
}
break

View File

@ -53,7 +53,7 @@ func NewServer(address string, handler func(*Conn), name ...string) *Server {
address: address,
handler: handler,
}
if len(name) > 0 {
if len(name) > 0 && name[0] != "" {
serverMapping.Set(name[0], s)
}
return s