mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 01:39:39 +08:00
fix: avoid data racing.
This commit is contained in:
@@ -2,6 +2,7 @@ package hrp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ const (
|
|||||||
type paramsType []map[string]interface{}
|
type paramsType []map[string]interface{}
|
||||||
|
|
||||||
type Iterator struct {
|
type Iterator struct {
|
||||||
|
sync.Mutex
|
||||||
data paramsType
|
data paramsType
|
||||||
strategy string // random, sequential
|
strategy string // random, sequential
|
||||||
iteration int
|
iteration int
|
||||||
@@ -64,6 +66,8 @@ func (iter *Iterator) HasNext() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (iter *Iterator) Next() (value map[string]interface{}) {
|
func (iter *Iterator) Next() (value map[string]interface{}) {
|
||||||
|
iter.Lock()
|
||||||
|
defer iter.Unlock()
|
||||||
iter.index++
|
iter.index++
|
||||||
if len(iter.data) == 0 {
|
if len(iter.data) == 0 {
|
||||||
return map[string]interface{}{}
|
return map[string]interface{}{}
|
||||||
|
|||||||
Reference in New Issue
Block a user