Skip to content

Commit

Permalink
refactor: include assert skipped to results
Browse files Browse the repository at this point in the history
  • Loading branch information
medcl committed Dec 12, 2024
1 parent 4c4f766 commit 9e07eef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
26 changes: 14 additions & 12 deletions loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ type LoadGenerator struct {
}

type LoadStats struct {
TotReqSize int64
TotRespSize int64
TotDuration time.Duration
MinRequestTime time.Duration
MaxRequestTime time.Duration
NumRequests int
NumErrs int
NumInvalid int
StatusCode map[int]int
TotReqSize int64
TotRespSize int64
TotDuration time.Duration
MinRequestTime time.Duration
MaxRequestTime time.Duration
NumRequests int
NumErrs int
NumAssertInvalid int
NumAssertSkipped int
StatusCode map[int]int
}

var (
Expand Down Expand Up @@ -163,7 +164,7 @@ func doRequest(config *LoaderConfig, globalCtx util.MapStr, req *fasthttp.Reques

if err != nil {
loadStats.NumErrs++
loadStats.NumInvalid++
loadStats.NumAssertInvalid++
}

if !config.RunnerConfig.NoSizeStats {
Expand Down Expand Up @@ -223,14 +224,15 @@ func doRequest(config *LoaderConfig, globalCtx util.MapStr, req *fasthttp.Reques
condition, buildErr := conditions.NewCondition(item.Assert)
if buildErr != nil {
if config.RunnerConfig.SkipInvalidAssert{
loadStats.NumAssertSkipped++
continue
}
log.Errorf("failed to build conditions while assert existed, error: %+v", buildErr)
loadStats.NumInvalid++
loadStats.NumAssertInvalid++
return
}
if !condition.Check(event) {
loadStats.NumInvalid++
loadStats.NumAssertInvalid++
if item.Request != nil {
log.Errorf("%s %s, assertion failed, skipping subsequent requests", item.Request.Method, item.Request.Url)
}
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func startLoader(cfg *LoaderConfig) *LoadStats {
loadGen.Stop()
case stats := <-statsAggregator:
aggStats.NumErrs += stats.NumErrs
aggStats.NumInvalid += stats.NumInvalid
aggStats.NumAssertInvalid += stats.NumAssertInvalid
aggStats.NumAssertSkipped += stats.NumAssertSkipped
aggStats.NumRequests += stats.NumRequests
aggStats.TotReqSize += stats.TotReqSize
aggStats.TotRespSize += stats.TotRespSize
Expand Down Expand Up @@ -217,7 +218,8 @@ func startLoader(cfg *LoaderConfig) *LoadStats {
}

if cfg.RunnerConfig.AssertInvalid {
fmt.Printf("Assert Invalid:\t%v\n", aggStats.NumInvalid)
fmt.Printf("Assert Invalid:\t\t%v\n", aggStats.NumAssertInvalid)
fmt.Printf("Assert Skipped:\t\t%v\n", aggStats.NumAssertSkipped)
}

for k, v := range aggStats.StatusCode {
Expand Down Expand Up @@ -440,7 +442,7 @@ func runLoaderConfig(config *LoaderConfig) int {

aggStats := startLoader(config)
if aggStats != nil {
if config.RunnerConfig.AssertInvalid && aggStats.NumInvalid > 0 {
if config.RunnerConfig.AssertInvalid && aggStats.NumAssertInvalid > 0 {
return 1
}
if config.RunnerConfig.AssertError && aggStats.NumErrs > 0 {
Expand Down

0 comments on commit 9e07eef

Please sign in to comment.