fix: pluginMap uses sync.Map to avoid data race

This commit is contained in:
徐聪
2022-08-01 17:04:39 +08:00
parent 44e844829d
commit c5a0a0fc27
4 changed files with 19 additions and 14 deletions
+8 -6
View File
@@ -101,11 +101,12 @@ func (b *HRPBoomer) Run(testcases ...ITestCase) {
// quit all plugins
defer func() {
if len(pluginMap) > 0 {
for _, plugin := range pluginMap {
pluginMap.Range(func(key, value interface{}) bool {
if plugin, ok := value.(funplugin.IPlugin); ok {
plugin.Quit()
}
}
return true
})
}()
taskSlice := b.ConvertTestCasesToBoomerTasks(testcases...)
@@ -283,11 +284,12 @@ func (b *HRPBoomer) PollTasks(ctx context.Context) {
func (b *HRPBoomer) PollTestCases(ctx context.Context) {
// quit all plugins
defer func() {
if len(pluginMap) > 0 {
for _, plugin := range pluginMap {
pluginMap.Range(func(key, value interface{}) bool {
if plugin, ok := value.(funplugin.IPlugin); ok {
plugin.Quit()
}
}
return true
})
}()
for {