fix: testcase compatibility in the worker

This commit is contained in:
徐聪
2022-07-29 19:57:05 +08:00
parent 88c25d26c4
commit b9f1468ae2
3 changed files with 27 additions and 24 deletions

View File

@@ -2,8 +2,6 @@ package hrp
import (
"fmt"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"golang.org/x/net/context"
"io/ioutil"
"os"
"path/filepath"
@@ -13,9 +11,11 @@ import (
"github.com/httprunner/funplugin"
"github.com/httprunner/httprunner/v4/hrp/internal/boomer"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/internal/json"
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
"github.com/rs/zerolog/log"
"golang.org/x/net/context"
)
func NewStandaloneBoomer(spawnCount int64, spawnRate float64) *HRPBoomer {
@@ -100,6 +100,15 @@ func (b *HRPBoomer) Run(testcases ...ITestCase) {
// report execution timing event
defer sdk.SendEvent(event.StartTiming("execution"))
// quit all plugins
defer func() {
if len(pluginMap) > 0 {
for _, plugin := range pluginMap {
plugin.Quit()
}
}
}()
taskSlice := b.ConvertTestCasesToBoomerTasks(testcases...)
b.Boomer.Run(taskSlice...)
@@ -113,15 +122,6 @@ func (b *HRPBoomer) ConvertTestCasesToBoomerTasks(testcases ...ITestCase) (taskS
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)

View File

@@ -285,15 +285,17 @@ func (r *HRPRunner) newCaseRunner(testcase *TestCase) (*testCaseRunner, error) {
// load plugin info to testcase config
if plugin != nil {
pluginPath, _ := locatePlugin(testcase.Config.Path)
pluginContent, err := builtin.ReadFile(pluginPath)
if err != nil {
return nil, err
}
tp := strings.Split(plugin.Path(), ".")
runner.parsedConfig.PluginSetting = &PluginConfig{
Path: pluginPath,
Content: pluginContent,
Type: tp[len(tp)-1],
if runner.parsedConfig.PluginSetting == nil {
pluginContent, err := builtin.ReadFile(pluginPath)
if err != nil {
return nil, err
}
tp := strings.Split(plugin.Path(), ".")
runner.parsedConfig.PluginSetting = &PluginConfig{
Path: pluginPath,
Content: pluginContent,
Type: tp[len(tp)-1],
}
}
}

View File

@@ -104,10 +104,6 @@ func (tc *TCase) ToTestCase(casePath string) (*TestCase, error) {
return nil, errors.New("invalid testcase format, missing teststeps!")
}
err := tc.MakeCompat()
if err != nil {
return nil, err
}
if tc.Config == nil {
tc.Config = &TConfig{Name: "please input testcase name"}
}
@@ -121,6 +117,11 @@ func (tc *TCase) toTestCase() (*TestCase, error) {
Config: tc.Config,
}
err := tc.MakeCompat()
if err != nil {
return nil, err
}
// locate project root dir by plugin path
projectRootDir, err := GetProjectRootDirPath(tc.Config.Path)
if err != nil {