39 lines
730 B
Go
39 lines
730 B
Go
package battletest
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/pb"
|
|
"math/rand"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// 压测组件
|
|
type worker struct {
|
|
module *BattleTest
|
|
report *pb.BattleReport
|
|
statistics []int64
|
|
testnum int32
|
|
}
|
|
|
|
func (this *worker) Worker(wg *sync.WaitGroup) {
|
|
defer wg.Done()
|
|
var (
|
|
stime time.Time
|
|
duration int64
|
|
)
|
|
locp:
|
|
for {
|
|
time.Sleep(time.Millisecond * time.Duration(100+rand.Int31n(900)))
|
|
stime = time.Now()
|
|
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
|
|
this.module.clientmgr.CheckBattle(ctx, this.report)
|
|
duration = time.Since(stime).Milliseconds()
|
|
this.statistics = append(this.statistics, duration)
|
|
this.testnum--
|
|
if this.testnum <= 0 {
|
|
break locp
|
|
}
|
|
}
|
|
}
|