mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-11 15:31:37 +08:00
fix: race error
This commit is contained in:
@@ -85,7 +85,7 @@ func TestStandaloneRun(t *testing.T) {
|
|||||||
|
|
||||||
b.Quit()
|
b.Quit()
|
||||||
|
|
||||||
if count != 10 {
|
if atomic.LoadInt64(&count) != 10 {
|
||||||
t.Error("count is", count, "expected: 10")
|
t.Error("count is", count, "expected: 10")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ func (r *runner) startSpawning(spawnCount int, spawnRate float64, spawnCompleteF
|
|||||||
r.stats.clearStatsChan <- true
|
r.stats.clearStatsChan <- true
|
||||||
r.stopChan = make(chan bool)
|
r.stopChan = make(chan bool)
|
||||||
|
|
||||||
r.numClients = 0
|
atomic.StoreInt32(&r.numClients, 0)
|
||||||
|
|
||||||
go r.spawnWorkers(spawnCount, r.stopChan, spawnCompleteFunc)
|
go r.spawnWorkers(spawnCount, r.stopChan, spawnCompleteFunc)
|
||||||
}
|
}
|
||||||
@@ -244,7 +244,7 @@ func (r *localRunner) run() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case data := <-r.stats.messageToRunnerChan:
|
case data := <-r.stats.messageToRunnerChan:
|
||||||
data["user_count"] = r.numClients
|
data["user_count"] = atomic.LoadInt32(&r.numClients)
|
||||||
r.outputOnEevent(data)
|
r.outputOnEevent(data)
|
||||||
case <-r.closeChan:
|
case <-r.closeChan:
|
||||||
r.stop()
|
r.stop()
|
||||||
|
|||||||
@@ -116,12 +116,7 @@ func (s *requestStats) get(name string, method string) (entry *statsEntry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestStats) clearAll() {
|
func (s *requestStats) clearAll() {
|
||||||
s.total = &statsEntry{
|
|
||||||
Name: "Total",
|
|
||||||
Method: "",
|
|
||||||
}
|
|
||||||
s.total.reset()
|
s.total.reset()
|
||||||
|
|
||||||
s.transactionPassed = 0
|
s.transactionPassed = 0
|
||||||
s.transactionFailed = 0
|
s.transactionFailed = 0
|
||||||
s.entries = make(map[string]*statsEntry)
|
s.entries = make(map[string]*statsEntry)
|
||||||
@@ -227,6 +222,8 @@ type statsEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *statsEntry) reset() {
|
func (s *statsEntry) reset() {
|
||||||
|
s.Name = ""
|
||||||
|
s.Method = ""
|
||||||
s.StartTime = time.Now().Unix()
|
s.StartTime = time.Now().Unix()
|
||||||
s.NumRequests = 0
|
s.NumRequests = 0
|
||||||
s.NumFailures = 0
|
s.NumFailures = 0
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func startMemoryProfile(file string, duration time.Duration) (err error) {
|
|||||||
|
|
||||||
log.Info().Dur("duration", duration).Msg("Start memory profiling")
|
log.Info().Dur("duration", duration).Msg("Start memory profiling")
|
||||||
time.AfterFunc(duration, func() {
|
time.AfterFunc(duration, func() {
|
||||||
err = pprof.WriteHeapProfile(f)
|
err := pprof.WriteHeapProfile(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to write memory profile")
|
log.Error().Err(err).Msg("failed to write memory profile")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user