update
This commit is contained in:
parent
340494ec96
commit
9fc9751ab7
24
lib/ai.go
24
lib/ai.go
@ -16,17 +16,16 @@ import (
|
||||
)
|
||||
|
||||
type MyAI struct {
|
||||
robots []*Robot
|
||||
scenes []*scene
|
||||
iscenes []IScene
|
||||
tickets Tickets //票池
|
||||
Obs Observer
|
||||
// useCount uint32 //计数(压入的用户数)
|
||||
useCountTotal uint32 //总数
|
||||
cache sync.Mutex //数据缓存锁
|
||||
lock sync.Mutex //合并数据锁
|
||||
config *storage.Config //配置
|
||||
ReportMap map[int]map[string]*Statistics //测试报告 key1:场景 key2:协议
|
||||
robots []*Robot
|
||||
scenes []*scene
|
||||
iscenes []IScene
|
||||
tickets Tickets //票池
|
||||
Obs Observer
|
||||
userCountTotal uint32 //总数
|
||||
cache sync.Mutex //数据缓存锁
|
||||
lock sync.Mutex //合并数据锁
|
||||
config *storage.Config //配置
|
||||
ReportMap map[int]map[string]*Statistics //测试报告 key1:场景 key2:协议
|
||||
}
|
||||
|
||||
func NewAI(aip AIParam) (*MyAI, error) {
|
||||
@ -76,7 +75,6 @@ func (m *MyAI) Start() bool {
|
||||
logrus.Warn("还未设置场景")
|
||||
return false
|
||||
}
|
||||
logrus.Info("测试中...")
|
||||
go func() {
|
||||
for {
|
||||
m.tickets.Take(int32(m.config.Global.UserCount), m.config.Global.IntervalS)
|
||||
@ -84,7 +82,7 @@ func (m *MyAI) Start() bool {
|
||||
robot := NewRobot(m)
|
||||
robot.SetScenes()
|
||||
m.AppendRobot(robot)
|
||||
atomic.AddUint32(&m.useCountTotal, 1)
|
||||
atomic.AddUint32(&m.userCountTotal, 1)
|
||||
m.Obs.Notify(EVENT_ROBOT, int32(1))
|
||||
robot.Start()
|
||||
}()
|
||||
|
18
lib/robot.go
18
lib/robot.go
@ -54,15 +54,15 @@ func NewRobot(ai *MyAI) *Robot {
|
||||
}
|
||||
robot.Store("sid", ai.config.Global.SId)
|
||||
|
||||
ai.Obs.AddListener(EVENT_CLOSECON, Listener{
|
||||
OnNotify: func(data interface{}, args ...interface{}) {
|
||||
d := data.(bool)
|
||||
if d {
|
||||
robot.prepareToStop()
|
||||
robot.conn.Close()
|
||||
}
|
||||
},
|
||||
})
|
||||
// ai.Obs.AddListener(EVENT_CLOSECON, Listener{
|
||||
// OnNotify: func(data interface{}, args ...interface{}) {
|
||||
// d := data.(bool)
|
||||
// if d {
|
||||
// robot.prepareToStop()
|
||||
// robot.conn.Close()
|
||||
// }
|
||||
// },
|
||||
// })
|
||||
return robot
|
||||
}
|
||||
|
||||
|
@ -59,13 +59,13 @@ func (gt *myTickets) init(total uint32) bool {
|
||||
}
|
||||
|
||||
func (gt *myTickets) Take(useCount, inteval int32) {
|
||||
atomic.AddInt32(>.count, 1)
|
||||
count := atomic.LoadInt32(>.count)
|
||||
if count >= int32(useCount) {
|
||||
time.Sleep(time.Duration(inteval) * time.Second)
|
||||
atomic.StoreInt32(>.count, 0)
|
||||
}
|
||||
<-gt.ticketCh
|
||||
atomic.AddInt32(>.count, 1)
|
||||
}
|
||||
|
||||
func (gt *myTickets) Return() {
|
||||
|
Loading…
Reference in New Issue
Block a user