diff --git a/lib/metrics.go b/lib/metrics.go index 5d7dbf9b..0a1a3d30 100644 --- a/lib/metrics.go +++ b/lib/metrics.go @@ -69,7 +69,7 @@ func (m *Metrics) Add(r *Result) { m.End = end } - if r.Code >= 200 && r.Code < 400 { + if r.Code >= 200 && r.Code < 400 && (r.Protocol != "gql" || r.Error == "") { m.success++ } diff --git a/lib/metrics_test.go b/lib/metrics_test.go index 8d22f1a4..6d79f061 100644 --- a/lib/metrics_test.go +++ b/lib/metrics_test.go @@ -22,13 +22,21 @@ func TestMetrics_Add(t *testing.T) { var got Metrics for i := 1; i <= 10000; i++ { + code := codes[i%len(codes)] + + protocol := "http" + if code == 200 && i%10 == 0 { + protocol = "gql" + } + got.Add(&Result{ - Code: codes[i%len(codes)], + Code: code, Timestamp: time.Unix(int64(i-1), 0), Latency: time.Duration(i) * time.Microsecond, BytesIn: 1024, BytesOut: 512, Error: errors[i%len(errors)], + Protocol: protocol, }) } got.Close() @@ -62,8 +70,8 @@ func TestMetrics_Add(t *testing.T) { Wait: duration("10ms"), Requests: 10000, Rate: 1.000100010001, - Throughput: 0.6667660098349737, - Success: 0.6667, + Throughput: 0.6333627029075878, + Success: 0.6333, StatusCodes: map[string]int{"500": 3333, "200": 3334, "302": 3333}, Errors: []string{"Internal server error"},