mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix: quit plugin
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user