mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
improve unit test case for gmutex
This commit is contained in:
@ -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()
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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 = ""
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"
|
||||
|
||||
Reference in New Issue
Block a user