Skip to content

Commit

Permalink
Sarthak | Adds support for TotalRequests and RequestsPerSecond in report
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakMakhija committed Aug 15, 2023
1 parent c6a4708 commit e0bb0c2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
15 changes: 13 additions & 2 deletions report/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ type Report struct {
Response ResponseMetrics
}

// TODO: Total connections, total requests, requests per second
// TODO: Total connections
type LoadMetrics struct {
TotalRequests uint
RequestsPerSecond float64
SuccessCount uint
ErrorCount uint
ErrorCountByType map[string]uint
Expand Down Expand Up @@ -64,7 +66,7 @@ func (reporter *Reporter) Run() {

func (reporter *Reporter) collectLoadMetrics() {
go func() {
totalGeneratedLoad := 0
totalGeneratedLoad := uint(0)
for load := range reporter.loadGenerationChannel {
totalGeneratedLoad++

Expand All @@ -91,6 +93,15 @@ func (reporter *Reporter) collectLoadMetrics() {
reporter.report.Load.LatestLoadSendTime = load.LoadGenerationTime
}
}
startTime := reporter.report.Load.EarliestLoadSendTime
timeToCompleteLoad := time.Now().Sub(startTime)

reporter.report.Load.TotalRequests = totalGeneratedLoad
reporter.report.Load.RequestsPerSecond = float64(
totalGeneratedLoad,
) / float64(
timeToCompleteLoad.Seconds(),
)
}()
}

Expand Down
14 changes: 14 additions & 0 deletions report/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ func TestReportWithAndWithoutErrorInGeneratingLoad(t *testing.T) {
assert.Equal(t, uint(1), reporter.report.Load.ErrorCount)
}

func TestReportWithTotalRequests(t *testing.T) {
loadGenerationChannel := make(chan workers.LoadGenerationResponse, 1)
reporter := NewReporter(loadGenerationChannel, nil)
reporter.Run()

loadGenerationChannel <- workers.LoadGenerationResponse{
Err: errors.New("test error"),
}
close(loadGenerationChannel)
time.Sleep(2 * time.Millisecond)

assert.Equal(t, uint(1), reporter.report.Load.TotalRequests)
}

func TestReportWithPayloadLengthInGeneratingLoad(t *testing.T) {
loadGenerationChannel := make(chan workers.LoadGenerationResponse, 1)
reporter := NewReporter(loadGenerationChannel, nil)
Expand Down
2 changes: 2 additions & 0 deletions report/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
var templateText = `
Summary:
LoadMetrics:
TotalRequests: {{ formatNumberUint .Load.TotalRequests }}
RequestsPerSecond: {{ formatNumberFloat .Load.RequestsPerSecond }}
SuccessCount: {{ formatNumberUint .Load.SuccessCount }}
ErrorCount: {{ formatNumberUint .Load.ErrorCount }}
TotalPayloadSize: {{ formatNumberInt64 .Load.TotalPayloadLengthBytes }} bytes
Expand Down
20 changes: 12 additions & 8 deletions report/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
var expected = `
Summary:
LoadMetrics:
SuccessCount: 1
TotalRequests: 1000
RequestsPerSecond: 55.3200
SuccessCount: 999
ErrorCount: 1
TotalPayloadSize: 20 bytes
TotalPayloadSize: 2000 bytes
AveragePayloadSize: 20.0000 bytes
EarliestLoadSendTime: August 21, 2023 04:14:00 IST
LatestLoadSendTime: August 21, 2023 04:14:00 IST
Expand All @@ -23,9 +25,9 @@ Summary:
[1] load error
ResponseMetrics:
SuccessCount: 1
SuccessCount: 1000
ErrorCount: 1
TotalResponsePayloadSize: 18 bytes
TotalResponsePayloadSize: 1800 bytes
AverageResponsePayloadSize: 18.0000 bytes
EarliestResponseReceivedTime: August 21, 2023 04:14:00 IST
LatestResponseReceivedTime: August 21, 2023 04:14:00 IST
Expand All @@ -40,19 +42,21 @@ func TestPrintsTheReport(t *testing.T) {

report := &Report{
Load: LoadMetrics{
SuccessCount: 1,
TotalRequests: 1000,
RequestsPerSecond: 55.32,
SuccessCount: 999,
ErrorCount: 1,
ErrorCountByType: map[string]uint{"load error": 1},
TotalPayloadLengthBytes: 20,
TotalPayloadLengthBytes: 2000,
AveragePayloadLengthBytes: 20.0,
EarliestLoadSendTime: time,
LatestLoadSendTime: time,
},
Response: ResponseMetrics{
SuccessCount: 1,
SuccessCount: 1000,
ErrorCount: 1,
ErrorCountByType: map[string]uint{"response error": 1},
TotalResponsePayloadLengthBytes: 18,
TotalResponsePayloadLengthBytes: 1800,
AverageResponsePayloadLengthBytes: 18.0,
EarliestResponseReceivedTime: time,
LatestResponseReceivedTime: time,
Expand Down

0 comments on commit e0bb0c2

Please sign in to comment.