functional/tester: fix racey map writes

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
release-3.4
Gyuho Lee 2018-04-12 13:21:52 -07:00
parent d69b7d28a0
commit 0a92ba66fa
1 changed files with 6 additions and 0 deletions

View File

@ -35,6 +35,7 @@ func (cs *compositeStresser) Stress() error {
}
func (cs *compositeStresser) Pause() (ems map[string]int) {
var emu sync.Mutex
ems = make(map[string]int)
var wg sync.WaitGroup
wg.Add(len(cs.stressers))
@ -43,7 +44,9 @@ func (cs *compositeStresser) Pause() (ems map[string]int) {
defer wg.Done()
errs := s.Pause()
for k, v := range errs {
emu.Lock()
ems[k] += v
emu.Unlock()
}
}(cs.stressers[i])
}
@ -52,6 +55,7 @@ func (cs *compositeStresser) Pause() (ems map[string]int) {
}
func (cs *compositeStresser) Close() (ems map[string]int) {
var emu sync.Mutex
ems = make(map[string]int)
var wg sync.WaitGroup
wg.Add(len(cs.stressers))
@ -60,7 +64,9 @@ func (cs *compositeStresser) Close() (ems map[string]int) {
defer wg.Done()
errs := s.Close()
for k, v := range errs {
emu.Lock()
ems[k] += v
emu.Unlock()
}
}(cs.stressers[i])
}