Merge pull request #43 from httprunner/refactor-case-runner

v0.3.1

- feat: set ulimit to 10240 before load testing
- fix: concurrent map writes in load testing
This commit is contained in:
debugtalk
2021-12-30 16:43:11 +08:00
committed by GitHub
20 changed files with 170 additions and 82 deletions
+7 -6
View File
@@ -52,19 +52,20 @@ func (b *hrpBoomer) Run(testcases ...ITestCase) {
} }
func (b *hrpBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task { func (b *hrpBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
hrpRunner := NewRunner(nil).SetDebug(b.debug)
config := testcase.Config.ToStruct() config := testcase.Config.ToStruct()
return &boomer.Task{ return &boomer.Task{
Name: config.Name, Name: config.Name,
Weight: config.Weight, Weight: config.Weight,
Fn: func() { Fn: func() {
runner := NewRunner(nil).SetDebug(b.debug).Reset() runner := hrpRunner.newCaseRunner(testcase)
testcaseSuccess := true // flag whole testcase result testcaseSuccess := true // flag whole testcase result
var transactionSuccess = true // flag current transaction result var transactionSuccess = true // flag current transaction result
startTime := time.Now() startTime := time.Now()
for _, step := range testcase.TestSteps { for index, step := range testcase.TestSteps {
stepData, err := runner.runStep(step, testcase.Config) stepData, err := runner.runStep(index)
if err != nil { if err != nil {
// step failed // step failed
var elapsed int64 var elapsed int64
@@ -77,8 +78,8 @@ func (b *hrpBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
testcaseSuccess = false testcaseSuccess = false
transactionSuccess = false transactionSuccess = false
if runner.failfast { if runner.hrpRunner.failfast {
log.Error().Err(err).Msg("abort running due to failfast setting") log.Error().Msg("abort running due to failfast setting")
break break
} }
log.Warn().Err(err).Msg("run step failed, continue next step") log.Warn().Err(err).Msg("run step failed, continue next step")
@@ -107,7 +108,7 @@ func (b *hrpBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
for name, transaction := range runner.transactions { for name, transaction := range runner.transactions {
if len(transaction) == 1 { if len(transaction) == 1 {
// if transaction end time not exists, use testcase end time instead // if transaction end time not exists, use testcase end time instead
duration := endTime.Sub(transaction[TransactionStart]) duration := endTime.Sub(transaction[transactionStart])
b.RecordTransaction(name, transactionSuccess, duration.Milliseconds(), 0) b.RecordTransaction(name, transactionSuccess, duration.Milliseconds(), 0)
} }
} }
+9 -5
View File
@@ -1,15 +1,19 @@
# Release History # Release History
## v0.3.0 (2021-12-22) ## v0.3.1 (2021-12-30)
- feat: set ulimit to 10240 before load testing
- fix: concurrent map writes in load testing
## v0.3.0 (2021-12-24)
- feat: implement `transaction` mechanism for load test - feat: implement `transaction` mechanism for load test
- feat: continue running next step when failure occurs with `--continue-on-failure` flag, default to failfast - feat: continue running next step when failure occurs with `--continue-on-failure` flag, default to failfast
- feat: spawn workers with `--spawn-rate` flag
- refactor: fork [boomer] as sub module
- feat: report GA events with version - feat: report GA events with version
- feat: run load test with the given limit and burst as rate limiter - feat: run load test with the given limit and burst as rate limiter, use `--spawn-count`, `--spawn-rate` and `--request-increase-rate` flag
- feat: report runner state to prometheus
- refactor: fork [boomer] as submodule initially and made a lot of changes
- change: update API models - change: update API models
- feat: report runner state
## v0.2.2 (2021-12-07) ## v0.2.2 (2021-12-07)
+12 -2
View File
@@ -4,9 +4,19 @@ One-stop solution for HTTP(S) testing.
### Synopsis ### Synopsis
hrp (HttpRunner+) aims to be a one-stop solution for HTTP(S) testing, covering API testing, load testing and digital experience monitoring (DEM). Enjoy! ✨ 🚀 ✨
██╗ ██╗████████╗████████╗██████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗
██║ ██║╚══██╔══╝╚══██╔══╝██╔══██╗██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗
███████║ ██║ ██║ ██████╔╝██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝
██╔══██║ ██║ ██║ ██╔═══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗
██║ ██║ ██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║
╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
hrp (HttpRunner+) aims to be a one-stop solution for HTTP(S) testing, covering API testing,
load testing and digital experience monitoring (DEM). Enjoy! ✨ 🚀 ✨
License: Apache-2.0 License: Apache-2.0
Website: https://httprunner.com
Github: https://github.com/httprunner/hrp Github: https://github.com/httprunner/hrp
Copyright 2021 debugtalk Copyright 2021 debugtalk
@@ -22,4 +32,4 @@ Copyright 2021 debugtalk
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files * [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
* [hrp run](hrp_run.md) - run API test * [hrp run](hrp_run.md) - run API test
###### Auto generated by spf13/cobra on 24-Dec-2021 ###### Auto generated by spf13/cobra on 30-Dec-2021
+1 -1
View File
@@ -38,4 +38,4 @@ hrp boom [flags]
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing. * [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 24-Dec-2021 ###### Auto generated by spf13/cobra on 30-Dec-2021
+1 -1
View File
@@ -23,4 +23,4 @@ hrp har2case harPath... [flags]
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing. * [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 24-Dec-2021 ###### Auto generated by spf13/cobra on 30-Dec-2021
+1 -1
View File
@@ -31,4 +31,4 @@ hrp run path... [flags]
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing. * [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 24-Dec-2021 ###### Auto generated by spf13/cobra on 30-Dec-2021
+1
View File
@@ -19,6 +19,7 @@ var boomCmd = &cobra.Command{
$ hrp boom examples/ # run testcases in specified folder`, $ hrp boom examples/ # run testcases in specified folder`,
Args: cobra.MinimumNArgs(1), Args: cobra.MinimumNArgs(1),
PreRun: func(cmd *cobra.Command, args []string) { PreRun: func(cmd *cobra.Command, args []string) {
boomer.SetUlimit(10240) // ulimit -n 10240
setLogLevel("WARN") // disable info logs for load testing setLogLevel("WARN") // disable info logs for load testing
}, },
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/httprunner/hrp/har2case" "github.com/httprunner/hrp/internal/har2case"
) )
// har2caseCmd represents the har2case command // har2caseCmd represents the har2case command
+11 -1
View File
@@ -15,9 +15,19 @@ import (
var RootCmd = &cobra.Command{ var RootCmd = &cobra.Command{
Use: "hrp", Use: "hrp",
Short: "One-stop solution for HTTP(S) testing.", Short: "One-stop solution for HTTP(S) testing.",
Long: `hrp (HttpRunner+) aims to be a one-stop solution for HTTP(S) testing, covering API testing, load testing and digital experience monitoring (DEM). Enjoy! ✨ 🚀 ✨ Long: `
██╗ ██╗████████╗████████╗██████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗
██║ ██║╚══██╔══╝╚══██╔══╝██╔══██╗██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗
███████║ ██║ ██║ ██████╔╝██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝
██╔══██║ ██║ ██║ ██╔═══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗
██║ ██║ ██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║
╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
hrp (HttpRunner+) aims to be a one-stop solution for HTTP(S) testing, covering API testing,
load testing and digital experience monitoring (DEM). Enjoy! ✨ 🚀 ✨
License: Apache-2.0 License: Apache-2.0
Website: https://httprunner.com
Github: https://github.com/httprunner/hrp Github: https://github.com/httprunner/hrp
Copyright 2021 debugtalk`, Copyright 2021 debugtalk`,
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
+32
View File
@@ -0,0 +1,32 @@
// +build !windows
package boomer
import (
"syscall"
"github.com/rs/zerolog/log"
)
// set resource limit
// ulimit -n 10240
func SetUlimit(limit uint64) {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Error().Err(err).Msg("get ulimit failed")
return
}
log.Info().Uint64("limit", rLimit.Cur).Msg("get current ulimit")
if rLimit.Cur >= limit {
return
}
rLimit.Cur = limit
log.Info().Uint64("limit", rLimit.Cur).Msg("set current ulimit")
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
log.Error().Err(err).Msg("set ulimit failed")
return
}
}
+12
View File
@@ -0,0 +1,12 @@
// +build windows
package boomer
import (
"github.com/rs/zerolog/log"
)
// set resource limit
func SetUlimit(limit uint64) {
log.Warn().Msg("windows does not support setting ulimit")
}
@@ -7,8 +7,8 @@ import (
) )
var ( var (
harPath = "../examples/har/demo.har" harPath = "../../examples/har/demo.har"
harPath2 = "../examples/har/postman-echo.har" harPath2 = "../../examples/har/postman-echo.har"
) )
func TestGenJSON(t *testing.T) { func TestGenJSON(t *testing.T) {
+1 -1
View File
@@ -1,3 +1,3 @@
package version package version
const VERSION = "v0.3.0" const VERSION = "v0.4.0"
+4 -4
View File
@@ -69,16 +69,16 @@ const (
stepTypeRendezvous stepType = "rendezvous" stepTypeRendezvous stepType = "rendezvous"
) )
type TransactionType string type transactionType string
const ( const (
TransactionStart TransactionType = "start" transactionStart transactionType = "start"
TransactionEnd TransactionType = "end" transactionEnd transactionType = "end"
) )
type Transaction struct { type Transaction struct {
Name string `json:"name" yaml:"name"` Name string `json:"name" yaml:"name"`
Type TransactionType `json:"type" yaml:"type"` Type transactionType `json:"type" yaml:"type"`
} }
type Rendezvous struct { type Rendezvous struct {
Name string `json:"name" yaml:"name"` // required Name string `json:"name" yaml:"name"` // required
+61 -46
View File
@@ -42,8 +42,6 @@ func NewRunner(t *testing.T) *hrpRunner {
}, },
Timeout: 30 * time.Second, Timeout: 30 * time.Second,
}, },
sessionVariables: make(map[string]interface{}),
transactions: make(map[string]map[TransactionType]time.Time),
} }
} }
@@ -52,20 +50,6 @@ type hrpRunner struct {
failfast bool failfast bool
debug bool debug bool
client *http.Client client *http.Client
sessionVariables map[string]interface{}
// transactions stores transaction timing info.
// key is transaction name, value is map of transaction type and time, e.g. start time and end time.
transactions map[string]map[TransactionType]time.Time
startTime time.Time // record start time of the testcase
}
// Reset clears runner session variables.
func (r *hrpRunner) Reset() *hrpRunner {
log.Info().Msg("[init] Reset session variables")
r.sessionVariables = make(map[string]interface{})
r.transactions = make(map[string]map[TransactionType]time.Time)
r.startTime = time.Now()
return r
} }
// SetFailfast configures whether to stop running when one step fails. // SetFailfast configures whether to stop running when one step fails.
@@ -108,14 +92,13 @@ func (r *hrpRunner) Run(testcases ...ITestCase) error {
// report execution timing event // report execution timing event
defer ga.SendEvent(event.StartTiming("execution")) defer ga.SendEvent(event.StartTiming("execution"))
r.Reset()
for _, iTestCase := range testcases { for _, iTestCase := range testcases {
testcase, err := iTestCase.ToTestCase() testcase, err := iTestCase.ToTestCase()
if err != nil { if err != nil {
log.Error().Err(err).Msg("[Run] convert ITestCase interface to TestCase struct failed") log.Error().Err(err).Msg("[Run] convert ITestCase interface to TestCase struct failed")
return err return err
} }
if err := r.runCase(testcase); err != nil { if err := r.newCaseRunner(testcase).run(); err != nil {
log.Error().Err(err).Msg("[Run] run testcase failed") log.Error().Err(err).Msg("[Run] run testcase failed")
return err return err
} }
@@ -123,20 +106,49 @@ func (r *hrpRunner) Run(testcases ...ITestCase) error {
return nil return nil
} }
func (r *hrpRunner) runCase(testcase *TestCase) error { func (r *hrpRunner) newCaseRunner(testcase *TestCase) *caseRunner {
config := testcase.Config caseRunner := &caseRunner{
TestCase: testcase,
hrpRunner: r,
}
caseRunner.reset()
return caseRunner
}
// caseRunner is used to run testcase and its steps.
// each testcase has its own caseRunner instance and share session variables.
type caseRunner struct {
*TestCase
hrpRunner *hrpRunner
sessionVariables map[string]interface{}
// transactions stores transaction timing info.
// key is transaction name, value is map of transaction type and time, e.g. start time and end time.
transactions map[string]map[transactionType]time.Time
startTime time.Time // record start time of the testcase
}
// reset clears runner session variables.
func (r *caseRunner) reset() *caseRunner {
log.Info().Msg("[init] Reset session variables")
r.sessionVariables = make(map[string]interface{})
r.transactions = make(map[string]map[transactionType]time.Time)
r.startTime = time.Now()
return r
}
func (r *caseRunner) run() error {
config := r.TestCase.Config
if err := r.parseConfig(config); err != nil { if err := r.parseConfig(config); err != nil {
return err return err
} }
log.Info().Str("testcase", config.Name()).Msg("run testcase start") log.Info().Str("testcase", config.Name()).Msg("run testcase start")
r.startTime = time.Now() r.startTime = time.Now()
for _, step := range testcase.TestSteps { for index := range r.TestCase.TestSteps {
_, err := r.runStep(step, config) _, err := r.runStep(index)
if err != nil { if err != nil {
if r.failfast { if r.hrpRunner.failfast {
log.Error().Err(err).Msg("abort running due to failfast setting") return errors.Wrap(err, "abort running due to failfast setting")
return err
} }
log.Warn().Err(err).Msg("run step failed, continue next step") log.Warn().Err(err).Msg("run step failed, continue next step")
} }
@@ -146,7 +158,10 @@ func (r *hrpRunner) runCase(testcase *TestCase) error {
return nil return nil
} }
func (r *hrpRunner) runStep(step IStep, config IConfig) (stepResult *stepData, err error) { func (r *caseRunner) runStep(index int) (stepResult *stepData, err error) {
config := r.TestCase.Config
step := r.TestCase.TestSteps[index]
// step type priority order: transaction > rendezvous > testcase > request // step type priority order: transaction > rendezvous > testcase > request
if stepTran, ok := step.(*StepTransaction); ok { if stepTran, ok := step.(*StepTransaction); ok {
// transaction step // transaction step
@@ -218,7 +233,7 @@ func (r *hrpRunner) runStep(step IStep, config IConfig) (stepResult *stepData, e
return stepResult, nil return stepResult, nil
} }
func (r *hrpRunner) runStepTransaction(transaction *Transaction) (stepResult *stepData, err error) { func (r *caseRunner) runStepTransaction(transaction *Transaction) (stepResult *stepData, err error) {
log.Info(). log.Info().
Str("name", transaction.Name). Str("name", transaction.Name).
Str("type", string(transaction.Type)). Str("type", string(transaction.Type)).
@@ -234,25 +249,25 @@ func (r *hrpRunner) runStepTransaction(transaction *Transaction) (stepResult *st
// create transaction if not exists // create transaction if not exists
if _, ok := r.transactions[transaction.Name]; !ok { if _, ok := r.transactions[transaction.Name]; !ok {
r.transactions[transaction.Name] = make(map[TransactionType]time.Time) r.transactions[transaction.Name] = make(map[transactionType]time.Time)
} }
// record transaction start time, override if already exists // record transaction start time, override if already exists
if transaction.Type == TransactionStart { if transaction.Type == transactionStart {
r.transactions[transaction.Name][TransactionStart] = time.Now() r.transactions[transaction.Name][transactionStart] = time.Now()
} }
// record transaction end time, override if already exists // record transaction end time, override if already exists
if transaction.Type == TransactionEnd { if transaction.Type == transactionEnd {
r.transactions[transaction.Name][TransactionEnd] = time.Now() r.transactions[transaction.Name][transactionEnd] = time.Now()
// if transaction start time not exists, use testcase start time instead // if transaction start time not exists, use testcase start time instead
if _, ok := r.transactions[transaction.Name][TransactionStart]; !ok { if _, ok := r.transactions[transaction.Name][transactionStart]; !ok {
r.transactions[transaction.Name][TransactionStart] = r.startTime r.transactions[transaction.Name][transactionStart] = r.startTime
} }
// calculate transaction duration // calculate transaction duration
duration := r.transactions[transaction.Name][TransactionEnd].Sub( duration := r.transactions[transaction.Name][transactionEnd].Sub(
r.transactions[transaction.Name][TransactionStart]) r.transactions[transaction.Name][transactionStart])
stepResult.elapsed = duration.Milliseconds() stepResult.elapsed = duration.Milliseconds()
log.Info().Str("name", transaction.Name).Dur("elapsed", duration).Msg("transaction") log.Info().Str("name", transaction.Name).Dur("elapsed", duration).Msg("transaction")
} }
@@ -260,7 +275,7 @@ func (r *hrpRunner) runStepTransaction(transaction *Transaction) (stepResult *st
return stepResult, nil return stepResult, nil
} }
func (r *hrpRunner) runStepRendezvous(rend *Rendezvous) (stepResult *stepData, err error) { func (r *caseRunner) runStepRendezvous(rend *Rendezvous) (stepResult *stepData, err error) {
log.Info(). log.Info().
Str("name", rend.Name). Str("name", rend.Name).
Float32("percent", rend.Percent). Float32("percent", rend.Percent).
@@ -275,7 +290,7 @@ func (r *hrpRunner) runStepRendezvous(rend *Rendezvous) (stepResult *stepData, e
return stepResult, nil return stepResult, nil
} }
func (r *hrpRunner) runStepRequest(step *TStep) (stepResult *stepData, err error) { func (r *caseRunner) runStepRequest(step *TStep) (stepResult *stepData, err error) {
stepResult = &stepData{ stepResult = &stepData{
name: step.Name, name: step.Name,
stepType: stepTypeRequest, stepType: stepTypeRequest,
@@ -388,7 +403,7 @@ func (r *hrpRunner) runStepRequest(step *TStep) (stepResult *stepData, err error
req.Host = u.Host req.Host = u.Host
// log & print request // log & print request
if r.debug { if r.hrpRunner.debug {
reqDump, err := httputil.DumpRequest(req, true) reqDump, err := httputil.DumpRequest(req, true)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "dump request failed") return nil, errors.Wrap(err, "dump request failed")
@@ -399,7 +414,7 @@ func (r *hrpRunner) runStepRequest(step *TStep) (stepResult *stepData, err error
// do request action // do request action
start := time.Now() start := time.Now()
resp, err := r.client.Do(req) resp, err := r.hrpRunner.client.Do(req)
stepResult.elapsed = time.Since(start).Milliseconds() stepResult.elapsed = time.Since(start).Milliseconds()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "do request failed") return nil, errors.Wrap(err, "do request failed")
@@ -407,7 +422,7 @@ func (r *hrpRunner) runStepRequest(step *TStep) (stepResult *stepData, err error
defer resp.Body.Close() defer resp.Body.Close()
// log & print response // log & print response
if r.debug { if r.hrpRunner.debug {
fmt.Println("==================== response ===================") fmt.Println("==================== response ===================")
respDump, err := httputil.DumpResponse(resp, true) respDump, err := httputil.DumpResponse(resp, true)
if err != nil { if err != nil {
@@ -418,7 +433,7 @@ func (r *hrpRunner) runStepRequest(step *TStep) (stepResult *stepData, err error
} }
// new response object // new response object
respObj, err := newResponseObject(r.t, resp) respObj, err := newResponseObject(r.hrpRunner.t, resp)
if err != nil { if err != nil {
err = errors.Wrap(err, "init ResponseObject error") err = errors.Wrap(err, "init ResponseObject error")
return return
@@ -443,7 +458,7 @@ func (r *hrpRunner) runStepRequest(step *TStep) (stepResult *stepData, err error
return stepResult, nil return stepResult, nil
} }
func (r *hrpRunner) runStepTestCase(step *TStep) (stepResult *stepData, err error) { func (r *caseRunner) runStepTestCase(step *TStep) (stepResult *stepData, err error) {
stepResult = &stepData{ stepResult = &stepData{
name: step.Name, name: step.Name,
stepType: stepTypeTestCase, stepType: stepTypeTestCase,
@@ -451,7 +466,7 @@ func (r *hrpRunner) runStepTestCase(step *TStep) (stepResult *stepData, err erro
} }
testcase := step.TestCase testcase := step.TestCase
start := time.Now() start := time.Now()
err = r.runCase(testcase) err = r.hrpRunner.newCaseRunner(testcase).run()
stepResult.elapsed = time.Since(start).Milliseconds() stepResult.elapsed = time.Since(start).Milliseconds()
if err != nil { if err != nil {
return stepResult, err return stepResult, err
@@ -460,7 +475,7 @@ func (r *hrpRunner) runStepTestCase(step *TStep) (stepResult *stepData, err erro
return stepResult, nil return stepResult, nil
} }
func (r *hrpRunner) parseConfig(config IConfig) error { func (r *caseRunner) parseConfig(config IConfig) error {
cfg := config.ToStruct() cfg := config.ToStruct()
// parse config variables // parse config variables
parsedVariables, err := parseVariables(cfg.Variables) parsedVariables, err := parseVariables(cfg.Variables)
@@ -487,7 +502,7 @@ func (r *hrpRunner) parseConfig(config IConfig) error {
return nil return nil
} }
func (r *hrpRunner) getSummary() *testCaseSummary { func (r *caseRunner) getSummary() *testCaseSummary {
return &testCaseSummary{} return &testCaseSummary{}
} }
+2 -2
View File
@@ -178,7 +178,7 @@ func (s *StepRequest) CallRefCase(tc *TestCase) *StepTestCaseWithOptionalArgs {
func (s *StepRequest) StartTransaction(name string) *StepTransaction { func (s *StepRequest) StartTransaction(name string) *StepTransaction {
s.step.Transaction = &Transaction{ s.step.Transaction = &Transaction{
Name: name, Name: name,
Type: TransactionStart, Type: transactionStart,
} }
return &StepTransaction{ return &StepTransaction{
step: s.step, step: s.step,
@@ -189,7 +189,7 @@ func (s *StepRequest) StartTransaction(name string) *StepTransaction {
func (s *StepRequest) EndTransaction(name string) *StepTransaction { func (s *StepRequest) EndTransaction(name string) *StepTransaction {
s.step.Transaction = &Transaction{ s.step.Transaction = &Transaction{
Name: name, Name: name,
Type: TransactionEnd, Type: transactionEnd,
} }
return &StepTransaction{ return &StepTransaction{
step: s.step, step: s.step,
+7 -4
View File
@@ -74,12 +74,15 @@ func TestRunRequestPostDataToStruct(t *testing.T) {
} }
func TestRunRequestRun(t *testing.T) { func TestRunRequestRun(t *testing.T) {
config := NewConfig("test").SetBaseURL("https://postman-echo.com") testcase := &TestCase{
runner := NewRunner(t).SetDebug(true) Config: NewConfig("test").SetBaseURL("https://postman-echo.com"),
if _, err := runner.runStep(stepGET, config); err != nil { TestSteps: []IStep{stepGET, stepPOSTData},
}
runner := NewRunner(t).SetDebug(true).newCaseRunner(testcase)
if _, err := runner.runStep(0); err != nil {
t.Fatalf("tStep.Run() error: %s", err) t.Fatalf("tStep.Run() error: %s", err)
} }
if _, err := runner.runStep(stepPOSTData, config); err != nil { if _, err := runner.runStep(1); err != nil {
t.Fatalf("tStepPOSTData.Run() error: %s", err) t.Fatalf("tStepPOSTData.Run() error: %s", err)
} }
} }