fix: quit plugin

This commit is contained in:
徐聪
2022-07-21 18:10:01 +08:00
parent 2f2ef937f4
commit 1e3d57027e
3 changed files with 18 additions and 21 deletions

View File

@@ -61,6 +61,15 @@ func (b *HRPBoomer) Run(testcases ...ITestCase) {
os.Exit(1)
}
// quit all plugins
defer func() {
if len(pluginMap) > 0 {
for _, plugin := range pluginMap {
plugin.Quit()
}
}
}()
for _, testcase := range testCases {
rendezvousList := initRendezvous(testcase, int64(b.GetSpawnCount()))
task := b.convertBoomerTask(testcase, rendezvousList)
@@ -71,12 +80,6 @@ func (b *HRPBoomer) Run(testcases ...ITestCase) {
}
func (b *HRPBoomer) Quit() {
b.pluginsMutex.Lock()
plugins := b.plugins
b.pluginsMutex.Unlock()
for _, plugin := range plugins {
plugin.Quit()
}
b.Boomer.Quit()
}

View File

@@ -3,10 +3,8 @@ package hrp
import (
"fmt"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"github.com/httprunner/funplugin"
"github.com/httprunner/funplugin/fungo"
@@ -79,14 +77,6 @@ func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err er
// add plugin instance to plugin map
pluginMap[pluginPath] = plugin
// catch Interrupt and SIGTERM signals to ensure plugin quitted
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
plugin.Quit()
}()
// report event for initializing plugin
event := sdk.EventTracking{
Category: "InitPlugin",

View File

@@ -184,6 +184,15 @@ func (r *HRPRunner) Run(testcases ...ITestCase) error {
return err
}
// quit all plugins
defer func() {
if len(pluginMap) > 0 {
for _, plugin := range pluginMap {
plugin.Quit()
}
}
}()
var runErr error
// run testcase one by one
for _, testcase := range testCases {
@@ -192,11 +201,6 @@ func (r *HRPRunner) Run(testcases ...ITestCase) error {
log.Error().Err(err).Msg("[Run] init session runner failed")
return err
}
defer func() {
if sessionRunner.parser.plugin != nil {
sessionRunner.parser.plugin.Quit()
}
}()
for it := sessionRunner.parametersIterator; it.HasNext(); {
err = sessionRunner.Start(it.Next())