mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-06 23:11:21 +08:00
fix: data race
This commit is contained in:
18
boomer.go
18
boomer.go
@@ -1,6 +1,7 @@
|
|||||||
package hrp
|
package hrp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
@@ -13,16 +14,18 @@ import (
|
|||||||
|
|
||||||
func NewBoomer(spawnCount int, spawnRate float64) *HRPBoomer {
|
func NewBoomer(spawnCount int, spawnRate float64) *HRPBoomer {
|
||||||
b := &HRPBoomer{
|
b := &HRPBoomer{
|
||||||
Boomer: boomer.NewStandaloneBoomer(spawnCount, spawnRate),
|
Boomer: boomer.NewStandaloneBoomer(spawnCount, spawnRate),
|
||||||
debug: false,
|
pluginsMutex: new(sync.RWMutex),
|
||||||
|
debug: false,
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
type HRPBoomer struct {
|
type HRPBoomer struct {
|
||||||
*boomer.Boomer
|
*boomer.Boomer
|
||||||
plugins []common.Plugin // each task has its own plugin process
|
plugins []common.Plugin // each task has its own plugin process
|
||||||
debug bool
|
pluginsMutex *sync.RWMutex // avoid data race
|
||||||
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDebug configures whether to log HTTP request and response content.
|
// SetDebug configures whether to log HTTP request and response content.
|
||||||
@@ -60,7 +63,10 @@ func (b *HRPBoomer) Run(testcases ...ITestCase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *HRPBoomer) Quit() {
|
func (b *HRPBoomer) Quit() {
|
||||||
for _, plugin := range b.plugins {
|
b.pluginsMutex.Lock()
|
||||||
|
plugins := b.plugins
|
||||||
|
b.pluginsMutex.Unlock()
|
||||||
|
for _, plugin := range plugins {
|
||||||
plugin.Quit()
|
plugin.Quit()
|
||||||
}
|
}
|
||||||
b.Boomer.Quit()
|
b.Boomer.Quit()
|
||||||
@@ -73,7 +79,9 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
|
|||||||
// each testcase has its own plugin process
|
// each testcase has its own plugin process
|
||||||
plugin, _ := initPlugin(config.Path)
|
plugin, _ := initPlugin(config.Path)
|
||||||
if plugin != nil {
|
if plugin != nil {
|
||||||
|
b.pluginsMutex.Lock()
|
||||||
b.plugins = append(b.plugins, plugin)
|
b.plugins = append(b.plugins, plugin)
|
||||||
|
b.pluginsMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
return &boomer.Task{
|
return &boomer.Task{
|
||||||
|
|||||||
Reference in New Issue
Block a user