Make Result.Error a string
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package vegeta
|
package vegeta
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -50,13 +49,14 @@ func hit(req *http.Request, res chan Result) {
|
|||||||
Timestamp: began,
|
Timestamp: began,
|
||||||
Timing: time.Since(began),
|
Timing: time.Since(began),
|
||||||
BytesOut: uint64(req.ContentLength),
|
BytesOut: uint64(req.ContentLength),
|
||||||
Error: err,
|
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err != nil {
|
||||||
|
result.Error = err.Error()
|
||||||
|
} else {
|
||||||
result.Code = uint16(r.StatusCode)
|
result.Code = uint16(r.StatusCode)
|
||||||
if body, err := ioutil.ReadAll(r.Body); err != nil {
|
if body, err := ioutil.ReadAll(r.Body); err != nil {
|
||||||
if result.Code < 200 || result.Code >= 300 {
|
if result.Code < 200 || result.Code >= 300 {
|
||||||
result.Error = errors.New(string(body))
|
result.Error = string(body)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.BytesIn = uint64(len(body))
|
result.BytesIn = uint64(len(body))
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ func NewMetrics(results []Result) *Metrics {
|
|||||||
if result.Code >= 200 && result.Code < 300 {
|
if result.Code >= 200 && result.Code < 300 {
|
||||||
m.TotalSuccess++
|
m.TotalSuccess++
|
||||||
}
|
}
|
||||||
if result.Error != nil {
|
if result.Error != "" {
|
||||||
errorSet[result.Error.Error()] = struct{}{}
|
errorSet[result.Error] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package vegeta
|
package vegeta
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewMetrics(t *testing.T) {
|
func TestNewMetrics(t *testing.T) {
|
||||||
m := NewMetrics([]Result{
|
m := NewMetrics([]Result{
|
||||||
Result{500, time.Now(), 100 * time.Millisecond, 10, 30, errors.New("Internal server error")},
|
Result{500, time.Now(), 100 * time.Millisecond, 10, 30, "Internal server error"},
|
||||||
Result{200, time.Now(), 20 * time.Millisecond, 20, 20, nil},
|
Result{200, time.Now(), 20 * time.Millisecond, 20, 20, ""},
|
||||||
Result{200, time.Now(), 30 * time.Millisecond, 30, 10, nil},
|
Result{200, time.Now(), 30 * time.Millisecond, 30, 10, ""},
|
||||||
})
|
})
|
||||||
|
|
||||||
for field, values := range map[string][]float64{
|
for field, values := range map[string][]float64{
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ type Result struct {
|
|||||||
Timing time.Duration
|
Timing time.Duration
|
||||||
BytesOut uint64
|
BytesOut uint64
|
||||||
BytesIn uint64
|
BytesIn uint64
|
||||||
Error error
|
Error string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Results is a slice of Result structs with encoding,
|
// Results is a slice of Result structs with encoding,
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import (
|
|||||||
|
|
||||||
func TestEncoding(t *testing.T) {
|
func TestEncoding(t *testing.T) {
|
||||||
results := Results{
|
results := Results{
|
||||||
Result{200, time.Now(), 100 * time.Millisecond, 10, 30, nil},
|
Result{200, time.Now(), 100 * time.Millisecond, 10, 30, ""},
|
||||||
Result{200, time.Now(), 20 * time.Millisecond, 20, 20, nil},
|
Result{200, time.Now(), 20 * time.Millisecond, 20, 20, ""},
|
||||||
Result{200, time.Now(), 30 * time.Millisecond, 30, 10, nil},
|
Result{200, time.Now(), 30 * time.Millisecond, 30, 10, ""},
|
||||||
}
|
}
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user