From 8b5ab846b22692e870cecb07f4a29ef7181b4091 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 30 Oct 2019 23:01:24 +0800 Subject: [PATCH] improve unit test case for gmutex --- .example/net/ghttp/server/websocket/echo/main-group.go | 4 ++-- .example/net/ghttp/server/websocket/echo/main.go | 2 +- net/ghttp/ghttp_server_router_group.go | 6 ++++-- os/gmutex/gmutex_unit_test.go | 10 ++++++---- util/gmode/gmode.go | 2 ++ 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.example/net/ghttp/server/websocket/echo/main-group.go b/.example/net/ghttp/server/websocket/echo/main-group.go index b4d0f70f6..fd7acd90e 100644 --- a/.example/net/ghttp/server/websocket/echo/main-group.go +++ b/.example/net/ghttp/server/websocket/echo/main-group.go @@ -11,7 +11,7 @@ func ws(r *ghttp.Request) { ws, err := r.WebSocket() if err != nil { glog.Error(err) - r.Exit() + return } for { msgType, msg, err := ws.ReadMessage() @@ -29,7 +29,7 @@ func main() { s.Group("").Bind([]ghttp.GroupItem{ {"ALL", "/ws", ws}, }) - + s.SetAccessLogEnabled(true) s.SetServerRoot(gfile.MainPkgPath()) s.SetPort(8199) s.Run() diff --git a/.example/net/ghttp/server/websocket/echo/main.go b/.example/net/ghttp/server/websocket/echo/main.go index f222bdcc5..daa3f419c 100644 --- a/.example/net/ghttp/server/websocket/echo/main.go +++ b/.example/net/ghttp/server/websocket/echo/main.go @@ -13,7 +13,7 @@ func main() { ws, err := r.WebSocket() if err != nil { glog.Error(err) - r.Exit() + return } for { msgType, msg, err := ws.ReadMessage() diff --git a/net/ghttp/ghttp_server_router_group.go b/net/ghttp/ghttp_server_router_group.go index 194d0aa0c..f58558cd1 100644 --- a/net/ghttp/ghttp_server_router_group.go +++ b/net/ghttp/ghttp_server_router_group.go @@ -56,8 +56,7 @@ func (s *Server) handlePreBindItems() { // 获取分组路由对象 func (s *Server) Group(prefix string, groups ...func(g *RouterGroup)) *RouterGroup { - // 自动识别并加上/前缀 - if prefix[0] != '/' { + if len(prefix) > 0 && prefix[0] != '/' { prefix = "/" + prefix } if prefix == "/" { @@ -77,6 +76,9 @@ func (s *Server) Group(prefix string, groups ...func(g *RouterGroup)) *RouterGro // 获取分组路由对象(绑定域名) func (d *Domain) Group(prefix string, groups ...func(g *RouterGroup)) *RouterGroup { + if len(prefix) > 0 && prefix[0] != '/' { + prefix = "/" + prefix + } if prefix == "/" { prefix = "" } diff --git a/os/gmutex/gmutex_unit_test.go b/os/gmutex/gmutex_unit_test.go index 08957b579..0560ae117 100644 --- a/os/gmutex/gmutex_unit_test.go +++ b/os/gmutex/gmutex_unit_test.go @@ -244,7 +244,7 @@ func Test_Mutex_TryRLockFunc(t *testing.T) { go func() { mu.LockFunc(func() { array.Append(1) - time.Sleep(300 * time.Millisecond) + time.Sleep(500 * time.Millisecond) }) }() go func() { @@ -255,15 +255,17 @@ func Test_Mutex_TryRLockFunc(t *testing.T) { }() for index := 0; index < 1000; index++ { go func() { - time.Sleep(400 * time.Millisecond) + time.Sleep(1000 * time.Millisecond) mu.TryRLockFunc(func() { array.Append(1) }) }() } - time.Sleep(100 * time.Millisecond) + time.Sleep(50 * time.Millisecond) gtest.Assert(array.Len(), 1) - time.Sleep(100 * time.Millisecond) + time.Sleep(150 * time.Millisecond) + gtest.Assert(array.Len(), 1) + time.Sleep(600 * time.Millisecond) gtest.Assert(array.Len(), 1) time.Sleep(600 * time.Millisecond) gtest.Assert(array.Len(), 1001) diff --git a/util/gmode/gmode.go b/util/gmode/gmode.go index c7c178d87..c77b0dc63 100644 --- a/util/gmode/gmode.go +++ b/util/gmode/gmode.go @@ -5,6 +5,8 @@ // You can obtain one at https://github.com/gogf/gf. // Package gmode provides release mode management for project. +// +// It uses string to mark the mode instead of integer, which is easy for configuration. package gmode import "github.com/gogf/gf/os/gfile"