mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
change: clean code
This commit is contained in:
@@ -148,7 +148,7 @@ func Init(path string) (Plugin, error) {
|
|||||||
}
|
}
|
||||||
var plugin Plugin
|
var plugin Plugin
|
||||||
|
|
||||||
// priority: hashicorp plugin > go plugin > builtin functions
|
// priority: hashicorp plugin > go plugin
|
||||||
// locate hashicorp plugin file
|
// locate hashicorp plugin file
|
||||||
pluginPath, err := locateFile(path, hashicorpGoPluginFile)
|
pluginPath, err := locateFile(path, hashicorpGoPluginFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -193,41 +193,36 @@ func (r *caseRunner) run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initPlugin(path string) (plugin common.Plugin, err error) {
|
func initPlugin(path string) (plugin common.Plugin, err error) {
|
||||||
defer func() {
|
|
||||||
if plugin == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var pluginType string
|
|
||||||
if _, ok := plugin.(*common.GoPlugin); ok {
|
|
||||||
pluginType = "go"
|
|
||||||
} else {
|
|
||||||
pluginType = "hashicorp"
|
|
||||||
}
|
|
||||||
|
|
||||||
// report event for initializing plugin
|
|
||||||
event := ga.EventTracking{
|
|
||||||
Category: "InitPlugin",
|
|
||||||
Action: fmt.Sprintf("Init %s plugin", pluginType),
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
event.Value = 1 // failed
|
|
||||||
}
|
|
||||||
go ga.SendEvent(event)
|
|
||||||
}()
|
|
||||||
plugin, err = common.Init(path)
|
plugin, err = common.Init(path)
|
||||||
|
if plugin == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
if plugin != nil {
|
plugin.Quit()
|
||||||
plugin.Quit()
|
|
||||||
}
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// report event for initializing plugin
|
||||||
|
var pluginType string
|
||||||
|
if _, ok := plugin.(*common.GoPlugin); ok {
|
||||||
|
pluginType = "go"
|
||||||
|
} else {
|
||||||
|
pluginType = "hashicorp"
|
||||||
|
}
|
||||||
|
event := ga.EventTracking{
|
||||||
|
Category: "InitPlugin",
|
||||||
|
Action: fmt.Sprintf("Init %s plugin", pluginType),
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
event.Value = 1 // failed
|
||||||
|
}
|
||||||
|
go ga.SendEvent(event)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user