mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
fix #1549: avoid duplicate creating plugins
This commit is contained in:
+26
-2
@@ -29,9 +29,33 @@ const (
|
|||||||
|
|
||||||
const projectInfoFile = "proj.json" // used for ensuring root project
|
const projectInfoFile = "proj.json" // used for ensuring root project
|
||||||
|
|
||||||
var pluginMap = sync.Map{} // used for reusing plugin instance
|
var (
|
||||||
|
pluginMap sync.Map // used for reusing plugin instance
|
||||||
|
pluginMutex sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err error) {
|
func initPlugin(path, venv string, logOn bool) (funplugin.IPlugin, error) {
|
||||||
|
if plugin, ok := pluginMap.Load(path); ok {
|
||||||
|
return plugin.(funplugin.IPlugin), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginMutex.Lock()
|
||||||
|
defer pluginMutex.Unlock()
|
||||||
|
|
||||||
|
if plugin, ok := pluginMap.Load(path); ok {
|
||||||
|
return plugin.(funplugin.IPlugin), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
p, err := initplugin(path, venv, logOn)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "init plugin failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginMap.Store(path, p)
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func initplugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err error) {
|
||||||
// plugin file not found
|
// plugin file not found
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user