Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #43 from httprunner/refactor-case-runner
Browse files Browse the repository at this point in the history
v0.3.1

- feat: set ulimit to 10240 before load testing
- fix: concurrent map writes in load testing
  • Loading branch information
debugtalk authored Dec 30, 2021
2 parents c1e239d + 17657d7 commit e98b1c8
Showing 20 changed files with 170 additions and 82 deletions.
13 changes: 7 additions & 6 deletions boomer.go
Original file line number Diff line number Diff line change
@@ -52,19 +52,20 @@ func (b *hrpBoomer) Run(testcases ...ITestCase) {
}

func (b *hrpBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
hrpRunner := NewRunner(nil).SetDebug(b.debug)
config := testcase.Config.ToStruct()
return &boomer.Task{
Name: config.Name,
Weight: config.Weight,
Fn: func() {
runner := NewRunner(nil).SetDebug(b.debug).Reset()
runner := hrpRunner.newCaseRunner(testcase)

testcaseSuccess := true // flag whole testcase result
var transactionSuccess = true // flag current transaction result

startTime := time.Now()
for _, step := range testcase.TestSteps {
stepData, err := runner.runStep(step, testcase.Config)
for index, step := range testcase.TestSteps {
stepData, err := runner.runStep(index)
if err != nil {
// step failed
var elapsed int64
@@ -77,8 +78,8 @@ func (b *hrpBoomer) convertBoomerTask(testcase *TestCase) *boomer.Task {
testcaseSuccess = false
transactionSuccess = false

if runner.failfast {
log.Error().Err(err).Msg("abort running due to failfast setting")
if runner.hrpRunner.failfast {
log.Error().Msg("abort running due to failfast setting")
break
}
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 {
if len(transaction) == 1 {
// 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)
}
}
14 changes: 9 additions & 5 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# 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: 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: 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
- feat: report runner state

## v0.2.2 (2021-12-07)

14 changes: 12 additions & 2 deletions docs/cmd/hrp.md
Original file line number Diff line number Diff line change
@@ -4,9 +4,19 @@ One-stop solution for HTTP(S) testing.

### 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
Website: https://httprunner.com
Github: https://github.com/httprunner/hrp
Copyright 2021 debugtalk

@@ -22,4 +32,4 @@ Copyright 2021 debugtalk
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
* [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
2 changes: 1 addition & 1 deletion docs/cmd/hrp_boom.md
Original file line number Diff line number Diff line change
@@ -38,4 +38,4 @@ hrp boom [flags]

* [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
2 changes: 1 addition & 1 deletion docs/cmd/hrp_har2case.md
Original file line number Diff line number Diff line change
@@ -23,4 +23,4 @@ hrp har2case harPath... [flags]

* [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
2 changes: 1 addition & 1 deletion docs/cmd/hrp_run.md
Original file line number Diff line number Diff line change
@@ -31,4 +31,4 @@ hrp run path... [flags]

* [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
3 changes: 2 additions & 1 deletion hrp/cmd/boom.go
Original file line number Diff line number Diff line change
@@ -19,7 +19,8 @@ var boomCmd = &cobra.Command{
$ hrp boom examples/ # run testcases in specified folder`,
Args: cobra.MinimumNArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
setLogLevel("WARN") // disable info logs for load testing
boomer.SetUlimit(10240) // ulimit -n 10240
setLogLevel("WARN") // disable info logs for load testing
},
Run: func(cmd *cobra.Command, args []string) {
var paths []hrp.ITestCase
2 changes: 1 addition & 1 deletion hrp/cmd/har2case.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

"github.com/httprunner/hrp/har2case"
"github.com/httprunner/hrp/internal/har2case"
)

// har2caseCmd represents the har2case command
12 changes: 11 additions & 1 deletion hrp/cmd/root.go
Original file line number Diff line number Diff line change
@@ -15,9 +15,19 @@ import (
var RootCmd = &cobra.Command{
Use: "hrp",
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
Website: https://httprunner.com
Github: https://github.com/httprunner/hrp
Copyright 2021 debugtalk`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
32 changes: 32 additions & 0 deletions internal/boomer/ulimit.go
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions internal/boomer/ulimit_windows.go
Original file line number Diff line number Diff line change
@@ -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")
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions har2case/core_test.go → internal/har2case/core_test.go
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ import (
)

var (
harPath = "../examples/har/demo.har"
harPath2 = "../examples/har/postman-echo.har"
harPath = "../../examples/har/demo.har"
harPath2 = "../../examples/har/postman-echo.har"
)

func TestGenJSON(t *testing.T) {
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/version/init.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package version

const VERSION = "v0.3.0"
const VERSION = "v0.4.0"
8 changes: 4 additions & 4 deletions models.go
Original file line number Diff line number Diff line change
@@ -69,16 +69,16 @@ const (
stepTypeRendezvous stepType = "rendezvous"
)

type TransactionType string
type transactionType string

const (
TransactionStart TransactionType = "start"
TransactionEnd TransactionType = "end"
transactionStart transactionType = "start"
transactionEnd transactionType = "end"
)

type Transaction struct {
Name string `json:"name" yaml:"name"`
Type TransactionType `json:"type" yaml:"type"`
Type transactionType `json:"type" yaml:"type"`
}
type Rendezvous struct {
Name string `json:"name" yaml:"name"` // required
Loading

0 comments on commit e98b1c8

Please sign in to comment.