From 9fc9751ab7a9e4240bb7eea54f90ddde8502ea32 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Wed, 4 Jan 2023 10:37:21 +0800 Subject: [PATCH] update --- lib/ai.go | 24 +++++++++++------------- lib/robot.go | 18 +++++++++--------- lib/tickets.go | 2 +- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/ai.go b/lib/ai.go index b9135c2..e379af8 100644 --- a/lib/ai.go +++ b/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() }() diff --git a/lib/robot.go b/lib/robot.go index c356754..16b3a25 100644 --- a/lib/robot.go +++ b/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 } diff --git a/lib/tickets.go b/lib/tickets.go index aa2b007..0a8687e 100644 --- a/lib/tickets.go +++ b/lib/tickets.go @@ -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() {