mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +08:00
fix: testcase compatibility in the worker
This commit is contained in:
@@ -2,8 +2,6 @@ package hrp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -13,9 +11,11 @@ import (
|
|||||||
|
|
||||||
"github.com/httprunner/funplugin"
|
"github.com/httprunner/funplugin"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/boomer"
|
"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/json"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewStandaloneBoomer(spawnCount int64, spawnRate float64) *HRPBoomer {
|
func NewStandaloneBoomer(spawnCount int64, spawnRate float64) *HRPBoomer {
|
||||||
@@ -100,6 +100,15 @@ func (b *HRPBoomer) Run(testcases ...ITestCase) {
|
|||||||
// report execution timing event
|
// report execution timing event
|
||||||
defer sdk.SendEvent(event.StartTiming("execution"))
|
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...)
|
taskSlice := b.ConvertTestCasesToBoomerTasks(testcases...)
|
||||||
|
|
||||||
b.Boomer.Run(taskSlice...)
|
b.Boomer.Run(taskSlice...)
|
||||||
@@ -113,15 +122,6 @@ func (b *HRPBoomer) ConvertTestCasesToBoomerTasks(testcases ...ITestCase) (taskS
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// quit all plugins
|
|
||||||
defer func() {
|
|
||||||
if len(pluginMap) > 0 {
|
|
||||||
for _, plugin := range pluginMap {
|
|
||||||
plugin.Quit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
for _, testcase := range testCases {
|
for _, testcase := range testCases {
|
||||||
rendezvousList := initRendezvous(testcase, int64(b.GetSpawnCount()))
|
rendezvousList := initRendezvous(testcase, int64(b.GetSpawnCount()))
|
||||||
task := b.convertBoomerTask(testcase, rendezvousList)
|
task := b.convertBoomerTask(testcase, rendezvousList)
|
||||||
|
|||||||
@@ -285,15 +285,17 @@ func (r *HRPRunner) newCaseRunner(testcase *TestCase) (*testCaseRunner, error) {
|
|||||||
// load plugin info to testcase config
|
// load plugin info to testcase config
|
||||||
if plugin != nil {
|
if plugin != nil {
|
||||||
pluginPath, _ := locatePlugin(testcase.Config.Path)
|
pluginPath, _ := locatePlugin(testcase.Config.Path)
|
||||||
pluginContent, err := builtin.ReadFile(pluginPath)
|
if runner.parsedConfig.PluginSetting == nil {
|
||||||
if err != nil {
|
pluginContent, err := builtin.ReadFile(pluginPath)
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
tp := strings.Split(plugin.Path(), ".")
|
}
|
||||||
runner.parsedConfig.PluginSetting = &PluginConfig{
|
tp := strings.Split(plugin.Path(), ".")
|
||||||
Path: pluginPath,
|
runner.parsedConfig.PluginSetting = &PluginConfig{
|
||||||
Content: pluginContent,
|
Path: pluginPath,
|
||||||
Type: tp[len(tp)-1],
|
Content: pluginContent,
|
||||||
|
Type: tp[len(tp)-1],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,10 +104,6 @@ func (tc *TCase) ToTestCase(casePath string) (*TestCase, error) {
|
|||||||
return nil, errors.New("invalid testcase format, missing teststeps!")
|
return nil, errors.New("invalid testcase format, missing teststeps!")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := tc.MakeCompat()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if tc.Config == nil {
|
if tc.Config == nil {
|
||||||
tc.Config = &TConfig{Name: "please input testcase name"}
|
tc.Config = &TConfig{Name: "please input testcase name"}
|
||||||
}
|
}
|
||||||
@@ -121,6 +117,11 @@ func (tc *TCase) toTestCase() (*TestCase, error) {
|
|||||||
Config: tc.Config,
|
Config: tc.Config,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := tc.MakeCompat()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// locate project root dir by plugin path
|
// locate project root dir by plugin path
|
||||||
projectRootDir, err := GetProjectRootDirPath(tc.Config.Path)
|
projectRootDir, err := GetProjectRootDirPath(tc.Config.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user