修复进度条
This commit is contained in:
parent
6976f85512
commit
702f09881b
15
lib/ai.go
15
lib/ai.go
@ -21,7 +21,7 @@ type myAI struct {
|
||||
iscenes []IScene
|
||||
tickets Tickets //票池
|
||||
Obs Observer
|
||||
useCount uint32 //计数(压入的用户数)
|
||||
// useCount uint32 //计数(压入的用户数)
|
||||
useCountTotal uint32 //总数
|
||||
lock sync.Mutex //合并数据锁
|
||||
config *storage.Config //配置
|
||||
@ -79,20 +79,15 @@ func (m *myAI) Start() bool {
|
||||
logrus.Info("测试中...")
|
||||
go func() {
|
||||
for {
|
||||
m.tickets.Take()
|
||||
uCount := atomic.LoadUint32(&m.useCount)
|
||||
if uCount >= uint32(m.config.Global.UserCount) {
|
||||
atomic.StoreUint32(&m.useCount, 0)
|
||||
time.Sleep(time.Duration(m.config.Global.IntervalS) * time.Second)
|
||||
}
|
||||
//加入机器人
|
||||
atomic.AddUint32(&m.useCount, 1)
|
||||
m.tickets.Take(int32(m.config.Global.UserCount), m.config.Global.IntervalS)
|
||||
go func() {
|
||||
robot := NewRobot(m.config)
|
||||
robot.SetScenes(m.iscenes)
|
||||
m.AppendRobot(robot)
|
||||
robot.Start()
|
||||
atomic.AddUint32(&m.useCountTotal, 1)
|
||||
m.Obs.Notify(EVENT_PROGRESS, int32(1))
|
||||
}()
|
||||
}
|
||||
}()
|
||||
|
||||
@ -102,7 +97,7 @@ func (m *myAI) Start() bool {
|
||||
total := atomic.LoadUint32(&m.useCountTotal)
|
||||
if total == m.config.Global.UserCountTotal {
|
||||
elipse := time.Since(start)
|
||||
logrus.Info("开始生成测试报告")
|
||||
logrus.Debug("开始生成测试报告")
|
||||
m.MergeResult()
|
||||
m.genReport(elipse)
|
||||
m.Obs.Notify(EVENT_PROGRESS, int32(0))
|
||||
|
@ -79,7 +79,7 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
t := time.Since(start)
|
||||
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "rsp": rsp, "since": t.String()}).Debug("接收消息")
|
||||
// logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "rsp": rsp, "since": t.String()}).Debug("接收消息")
|
||||
var name string
|
||||
if r.scene != nil {
|
||||
name = r.scene.Info().Name
|
||||
@ -109,7 +109,7 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
||||
return pb.ErrorCode_SystemError
|
||||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "req": req}).Debug("发送消息")
|
||||
// logrus.WithFields(logrus.Fields{"MainType": mainType, "SubType": subType, "req": req}).Debug("发送消息")
|
||||
for {
|
||||
_, data, err := r.conn.ReadMessage()
|
||||
if err != nil {
|
||||
@ -133,7 +133,6 @@ func (r *Robot) SendMsg(mainType, subType string, req proto.Message, rsp proto.M
|
||||
if !ProtoUnmarshal(msg, rsp) {
|
||||
break
|
||||
}
|
||||
logrus.Info(rsp.Code)
|
||||
return rsp.Code
|
||||
}
|
||||
}
|
||||
@ -255,7 +254,7 @@ func (m *Robot) SendResult(result *CallResult) bool {
|
||||
}
|
||||
select {
|
||||
case m.resultCh <- result:
|
||||
logrus.WithField("res", result).Debug("发送结果")
|
||||
// logrus.WithField("res", result).Debug("发送结果")
|
||||
return true
|
||||
default:
|
||||
m.printIgnoredResult(result, "通道满了")
|
||||
|
@ -3,12 +3,14 @@ package lib
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Tickets 表示Goroutine票池的接口。
|
||||
type Tickets interface {
|
||||
// 拿走一张票。
|
||||
Take()
|
||||
Take(useCount, inteval int32)
|
||||
// 归还一张票。
|
||||
Return()
|
||||
// 票池是否已被激活。
|
||||
@ -24,6 +26,7 @@ type myTickets struct {
|
||||
total uint32 // 票的总数。
|
||||
ticketCh chan struct{} // 票的容器。
|
||||
active bool // 票池是否已被激活。
|
||||
count int32
|
||||
}
|
||||
|
||||
// NewTickets 会新建一个Goroutine票池。
|
||||
@ -55,7 +58,13 @@ func (gt *myTickets) init(total uint32) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (gt *myTickets) Take() {
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user