diff --git a/TODO b/TODO new file mode 100644 index 0000000..730d279 --- /dev/null +++ b/TODO @@ -0,0 +1,9 @@ +1. Integrate blast.go in main +2. Format report (unnecessary new lines) +3. Add total connections in the report +4. Add total responses in the report +5. Validate the options in main +6. Run against a sample server + - with input from a file + - with input from a process +7. Take a look at TODOs diff --git a/report/reporter.go b/report/reporter.go index 0efd27d..9b97f14 100644 --- a/report/reporter.go +++ b/report/reporter.go @@ -38,10 +38,12 @@ type ResponseMetrics struct { } type Reporter struct { - report *Report - totalLoadReportedTillNow atomic.Uint64 - loadGenerationChannel chan LoadGenerationResponse - responseChannel chan SubjectServerResponse + report *Report + totalLoadReportedTillNow atomic.Uint64 + loadGenerationChannel chan LoadGenerationResponse + responseChannel chan SubjectServerResponse + loadMetricsDoneChannel chan struct{} + responseMetricsDoneChannel chan struct{} } func NewLoadGenerationMetricsCollectingReporter( @@ -56,8 +58,10 @@ func NewLoadGenerationMetricsCollectingReporter( IsAvailableForReporting: false, }, }, - loadGenerationChannel: loadGenerationChannel, - responseChannel: nil, + loadGenerationChannel: loadGenerationChannel, + responseChannel: nil, + loadMetricsDoneChannel: make(chan struct{}), + responseMetricsDoneChannel: nil, } } @@ -75,8 +79,10 @@ func NewResponseMetricsCollectingReporter( ErrorCountByType: make(map[string]uint), }, }, - loadGenerationChannel: loadGenerationChannel, - responseChannel: responseChannel, + loadGenerationChannel: loadGenerationChannel, + responseChannel: responseChannel, + loadMetricsDoneChannel: make(chan struct{}), + responseMetricsDoneChannel: make(chan struct{}), } } @@ -88,6 +94,11 @@ func (reporter *Reporter) Run() { } func (reporter *Reporter) PrintReport(writer io.Writer) { + println("printing report...") + <-reporter.loadMetricsDoneChannel + if reporter.responseMetricsDoneChannel != nil { + <-reporter.responseMetricsDoneChannel + } print(writer, reporter.report) } @@ -128,6 +139,7 @@ func (reporter *Reporter) collectLoadMetrics() { reporter.report.Load.TotalTime = timeToCompleteLoad reporter.report.Load.TotalRequests = totalGeneratedLoad + close(reporter.loadMetricsDoneChannel) }() } @@ -168,5 +180,6 @@ func (reporter *Reporter) collectResponseMetrics() { timeToCompleteResponses := reporter.report.Response.LatestResponseReceivedTime. Sub(reporter.report.Response.EarliestResponseReceivedTime) reporter.report.Response.TotalTime = timeToCompleteResponses + close(reporter.responseMetricsDoneChannel) }() } diff --git a/report/template.go b/report/template.go index 528f2d0..8f49e75 100644 --- a/report/template.go +++ b/report/template.go @@ -26,6 +26,7 @@ Summary: {{ if eq (.Response.IsAvailableForReporting) true }} ResponseMetrics: + TotalResponses: {{ formatNumberUint .Response.TotalResponses }} SuccessCount: {{ formatNumberUint .Response.SuccessCount }} ErrorCount: {{ formatNumberUint .Response.ErrorCount }} TotalResponsePayloadSize: {{ humanizePayloadSize .Response.TotalResponsePayloadLengthBytes }} diff --git a/report/template_test.go b/report/template_test.go index c8d8e22..63a6760 100644 --- a/report/template_test.go +++ b/report/template_test.go @@ -27,7 +27,8 @@ Summary: ResponseMetrics: - SuccessCount: 1000 + TotalResponses: 1000 + SuccessCount: 999 ErrorCount: 1 TotalResponsePayloadSize: 1.8 kB AverageResponsePayloadSize: 18 B @@ -58,7 +59,8 @@ Summary: TotalTime: tenSecondsLater.Sub(startTime), }, Response: ResponseMetrics{ - SuccessCount: 1000, + TotalResponses: 1000, + SuccessCount: 999, ErrorCount: 1, ErrorCountByType: map[string]uint{"response error": 1}, TotalResponsePayloadLengthBytes: 1800, diff --git a/tests/blast_integration_test.go b/tests/blast_integration_test.go index f268cd6..161cc9c 100644 --- a/tests/blast_integration_test.go +++ b/tests/blast_integration_test.go @@ -104,6 +104,7 @@ func TestBlastWithLoadGenerationAndResponseReading(t *testing.T) { output := string(buffer.Bytes()) assert.True(t, strings.Contains(output, "ResponseMetrics")) + assert.True(t, strings.Contains(output, "TotalResponses: 20")) assert.True(t, strings.Contains(output, "SuccessCount: 20")) assert.True(t, strings.Contains(output, "ErrorCount: 0")) assert.True(t, strings.Contains(output, "TotalPayloadSize: 200 B"))