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