HTTP load generator, ApacheBench (ab) replacement
Go
Introduced some changes based on rakyll suggestions
Vasilis Keramidas41cbfb5c77d3
diff --git a/commands/boom.go b/commands/boom.goindex 4818bca..7d2c4ea 100644--- a/commands/boom.go+++ b/commands/boom.go@@ -27,7 +27,7 @@ type result struct {err errorstatusCode intduration time.Duration- ContentLength int64+ contentLength int64}type ReqOpts struct {diff --git a/commands/print.go b/commands/print.goindex 212b451..5a9775e 100644--- a/commands/print.go+++ b/commands/print.go@@ -62,8 +62,8 @@ func (r *report) finalize(total time.Duration) {r.lats = append(r.lats, res.duration.Seconds())r.avgTotal += res.duration.Seconds()r.statusCodeDist[res.statusCode]++- if res.ContentLength > 0 {- r.sizeTotal += res.ContentLength+ if res.contentLength > 0 {+ r.sizeTotal += res.contentLength}}default:@@ -94,8 +94,8 @@ func (r *report) print() {fmt.Printf(" Average:\t%4.4f secs.\n", r.average)fmt.Printf(" Requests/sec:\t%4.4f\n", r.rps)if r.sizeTotal > 0 {- fmt.Printf(" Total Data Recieved:\t%d bytes\n", r.sizeTotal)- fmt.Printf(" Response Size per request:\t%d bytes\n", r.sizeTotal/int64(len(r.lats)))+ fmt.Printf(" Total Data Recieved:\t%d bytes.\n", r.sizeTotal)+ fmt.Printf(" Response Size per Request:\t%d bytes.\n", r.sizeTotal/int64(len(r.lats)))}r.printStatusCodes()r.printHistogram()diff --git a/commands/run.go b/commands/run.goindex 5a05183..9ae26b3 100644--- a/commands/run.go+++ b/commands/run.go@@ -57,7 +57,7 @@ func (b *Boom) worker(ch chan *http.Request) {statusCode: code,duration: time.Now().Sub(s),err: err,- ContentLength: size,+ contentLength: size,}}}diff --git a/commands/run_test.go b/commands/run_test.goindex f07f8be..83bd60d 100644--- a/commands/run_test.go+++ b/commands/run_test.go@@ -141,3 +141,46 @@ func TestBody(t *testing.T) {t.Errorf("Expected to boom 10 times, found %v", count)}}++func TestContentLengthIfExists(t *testing.T) {+ handler := func(w http.ResponseWriter, r *http.Request) {+ w.Header().Set("Content-Length", "20")+ }+ server := httptest.NewServer(http.HandlerFunc(handler))+ defer server.Close()++ boom := &Boom{+ Req: &ReqOpts{+ Method: "GET",+ Url: server.URL,+ },+ N: 10,+ C: 1,+ }+ boom.Run()++ if boom.rpt.sizeTotal != 200 {+ t.Errorf("Expected Total Data Recieved 200 bytes, found %v", boom.rpt.sizeTotal)+ }+}++func TestContentLengthIfDontExists(t *testing.T) {+ handler := func(w http.ResponseWriter, r *http.Request) {+ }+ server := httptest.NewServer(http.HandlerFunc(handler))+ defer server.Close()++ boom := &Boom{+ Req: &ReqOpts{+ Method: "GET",+ Url: server.URL,+ },+ N: 10,+ C: 1,+ }+ boom.Run()++ if boom.rpt.sizeTotal != 0 {+ t.Errorf("Expected Total Data Recieved 200 bytes, found %v", boom.rpt.sizeTotal)+ }+}