mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-08 01:09:44 +08:00
fix #1549: avoid duplicate creating plugins
This commit is contained in:
@@ -24,7 +24,7 @@ func TestLoadCurlCase(t *testing.T) {
|
|||||||
if !assert.EqualValues(t, "GET", tCase.TestSteps[0].Request.Method) {
|
if !assert.EqualValues(t, "GET", tCase.TestSteps[0].Request.Method) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
if !assert.Equal(t, "https://httpbin.org", tCase.TestSteps[0].Request.URL) {
|
if !assert.Equal(t, "http://httpbin.org", tCase.TestSteps[0].Request.URL) {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,31 +31,10 @@ const projectInfoFile = "proj.json" // used for ensuring root project
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
pluginMap sync.Map // used for reusing plugin instance
|
pluginMap sync.Map // used for reusing plugin instance
|
||||||
pluginMutex sync.Mutex
|
pluginMutex sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func initPlugin(path, venv string, logOn bool) (funplugin.IPlugin, error) {
|
func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err 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
|
||||||
@@ -66,6 +45,9 @@ func initplugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err er
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluginMutex.Lock()
|
||||||
|
defer pluginMutex.Unlock()
|
||||||
|
|
||||||
// reuse plugin instance if it already initialized
|
// reuse plugin instance if it already initialized
|
||||||
if p, ok := pluginMap.Load(pluginPath); ok {
|
if p, ok := pluginMap.Load(pluginPath); ok {
|
||||||
return p.(funplugin.IPlugin), nil
|
return p.(funplugin.IPlugin), nil
|
||||||
|
|||||||
Reference in New Issue
Block a user