mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 07:21:23 +08:00
fix: reuse plugin instance if it already initialized
This commit is contained in:
@@ -27,6 +27,8 @@ const (
|
|||||||
|
|
||||||
const projectInfoFile = "proj.json" // used for ensuring root project
|
const projectInfoFile = "proj.json" // used for ensuring root project
|
||||||
|
|
||||||
|
var pluginMap = map[string]funplugin.IPlugin{} // used for reusing plugin instance
|
||||||
|
|
||||||
func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err error) {
|
func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err error) {
|
||||||
// plugin file not found
|
// plugin file not found
|
||||||
if path == "" {
|
if path == "" {
|
||||||
@@ -37,6 +39,11 @@ func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err er
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reuse plugin instance if it already initialized
|
||||||
|
if p, ok := pluginMap[pluginPath]; ok {
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
|
||||||
pluginOptions := []funplugin.Option{funplugin.WithLogOn(logOn)}
|
pluginOptions := []funplugin.Option{funplugin.WithLogOn(logOn)}
|
||||||
|
|
||||||
if strings.HasSuffix(pluginPath, ".py") {
|
if strings.HasSuffix(pluginPath, ".py") {
|
||||||
@@ -69,6 +76,9 @@ func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add plugin instance to plugin map
|
||||||
|
pluginMap[pluginPath] = plugin
|
||||||
|
|
||||||
// catch Interrupt and SIGTERM signals to ensure plugin quitted
|
// catch Interrupt and SIGTERM signals to ensure plugin quitted
|
||||||
c := make(chan os.Signal)
|
c := make(chan os.Signal)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|||||||
Reference in New Issue
Block a user