fix: race error

This commit is contained in:
debugtalk
2021-12-23 17:26:42 +08:00
parent 81b4f6451e
commit 970734607e
4 changed files with 6 additions and 9 deletions

View File

@@ -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")
}

View File

@@ -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()

View File

@@ -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

View File

@@ -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")
}