From 6348a1b7df0e174f3b426231916bba483cae37ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senart?= Date: Tue, 10 Sep 2013 21:46:28 +0100 Subject: [PATCH] Make Result.Error a string --- lib/attack.go | 8 ++++---- lib/metrics.go | 4 ++-- lib/metrics_test.go | 7 +++---- lib/results.go | 2 +- lib/results_test.go | 6 +++--- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/attack.go b/lib/attack.go index ef671ee..2aa9b9e 100644 --- a/lib/attack.go +++ b/lib/attack.go @@ -1,7 +1,6 @@ package vegeta import ( - "errors" "io/ioutil" "net/http" "time" @@ -50,13 +49,14 @@ func hit(req *http.Request, res chan Result) { Timestamp: began, Timing: time.Since(began), BytesOut: uint64(req.ContentLength), - Error: err, } - if err == nil { + if err != nil { + result.Error = err.Error() + } else { result.Code = uint16(r.StatusCode) if body, err := ioutil.ReadAll(r.Body); err != nil { if result.Code < 200 || result.Code >= 300 { - result.Error = errors.New(string(body)) + result.Error = string(body) } } else { result.BytesIn = uint64(len(body)) diff --git a/lib/metrics.go b/lib/metrics.go index 1588b1f..6592156 100644 --- a/lib/metrics.go +++ b/lib/metrics.go @@ -37,8 +37,8 @@ func NewMetrics(results []Result) *Metrics { if result.Code >= 200 && result.Code < 300 { m.TotalSuccess++ } - if result.Error != nil { - errorSet[result.Error.Error()] = struct{}{} + if result.Error != "" { + errorSet[result.Error] = struct{}{} } } diff --git a/lib/metrics_test.go b/lib/metrics_test.go index 8d17ed5..94571ab 100644 --- a/lib/metrics_test.go +++ b/lib/metrics_test.go @@ -1,16 +1,15 @@ package vegeta import ( - "errors" "testing" "time" ) func TestNewMetrics(t *testing.T) { m := NewMetrics([]Result{ - Result{500, time.Now(), 100 * time.Millisecond, 10, 30, errors.New("Internal server error")}, - Result{200, time.Now(), 20 * time.Millisecond, 20, 20, nil}, - Result{200, time.Now(), 30 * time.Millisecond, 30, 10, nil}, + Result{500, time.Now(), 100 * time.Millisecond, 10, 30, "Internal server error"}, + Result{200, time.Now(), 20 * time.Millisecond, 20, 20, ""}, + Result{200, time.Now(), 30 * time.Millisecond, 30, 10, ""}, }) for field, values := range map[string][]float64{ diff --git a/lib/results.go b/lib/results.go index 75c84dd..5d8a530 100644 --- a/lib/results.go +++ b/lib/results.go @@ -15,7 +15,7 @@ type Result struct { Timing time.Duration BytesOut uint64 BytesIn uint64 - Error error + Error string } // Results is a slice of Result structs with encoding, diff --git a/lib/results_test.go b/lib/results_test.go index b0053fe..c42847a 100644 --- a/lib/results_test.go +++ b/lib/results_test.go @@ -9,9 +9,9 @@ import ( func TestEncoding(t *testing.T) { results := Results{ - Result{200, time.Now(), 100 * time.Millisecond, 10, 30, nil}, - Result{200, time.Now(), 20 * time.Millisecond, 20, 20, nil}, - Result{200, time.Now(), 30 * time.Millisecond, 30, 10, nil}, + Result{200, time.Now(), 100 * time.Millisecond, 10, 30, ""}, + Result{200, time.Now(), 20 * time.Millisecond, 20, 20, ""}, + Result{200, time.Now(), 30 * time.Millisecond, 30, 10, ""}, } buffer := &bytes.Buffer{}