functional/tester: fix racey map writes

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee
2018-04-12 13:21:52 -07:00
parent d69b7d28a0
commit 0a92ba66fa

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])
}