Skip to content

Commit

Permalink
add total request error count in summary
Browse files Browse the repository at this point in the history
  • Loading branch information
bengadbois committed Jun 16, 2024
1 parent 1eac89c commit e0a1aca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func CreateTextSummary(reqStatSummary RequestStatSummary) string {
}
summary += " (" + fmt.Sprintf("%.2f", 100*float64(reqStatSummary.statusCodes[code])/float64(totalResponses)) + "%)\n"
}

summary += fmt.Sprintf("\nErrors\nFailed requests: %d\n", reqStatSummary.errorCount)
return summary
}

Expand Down
2 changes: 2 additions & 0 deletions lib/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type RequestStatSummary struct {
maxDataTransferred int //bytes
minDataTransferred int //bytes
totalDataTransferred int //bytes
errorCount int
}

//CreateRequestsStats creates a statistical summary out of the individual RequestStats
Expand All @@ -55,6 +56,7 @@ func CreateRequestsStats(requestStats []RequestStat) RequestStatSummary {
nonErrCount := 0
for i := 0; i < len(requestStats); i++ {
if requestStats[i].Error != nil {
summary.errorCount++
continue
}
nonErrCount++
Expand Down
5 changes: 5 additions & 0 deletions lib/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestCreateRequestsStats(t *testing.T) {
startTime: time.Unix(1000, 0),
endTime: time.Unix(2000, 0),
statusCodes: map[int]int{200: 1},
errorCount: 0,
},
},
{
Expand All @@ -47,6 +48,7 @@ func TestCreateRequestsStats(t *testing.T) {
startTime: time.Unix(1000, 0),
endTime: time.Unix(2000, 0),
statusCodes: map[int]int{200: 2},
errorCount: 0,
},
},
{
Expand All @@ -63,6 +65,7 @@ func TestCreateRequestsStats(t *testing.T) {
startTime: time.Unix(1000, 0),
endTime: time.Unix(2000, 0),
statusCodes: map[int]int{},
errorCount: 2,
},
},
{
Expand All @@ -88,6 +91,7 @@ func TestCreateRequestsStats(t *testing.T) {
maxDataTransferred: 600,
minDataTransferred: 100,
totalDataTransferred: 2100,
errorCount: 1,
},
},
{
Expand All @@ -113,6 +117,7 @@ func TestCreateRequestsStats(t *testing.T) {
maxDataTransferred: 600,
minDataTransferred: 100,
totalDataTransferred: 2100,
errorCount: 1,
},
},
}
Expand Down

0 comments on commit e0a1aca

Please sign in to comment.