summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-03-22 11:35:46 +0100
committerMartin Polden <mpolden@mpolden.no>2023-03-23 17:57:37 +0100
commitd3b27ba2ebde8d700d0903ff3b33dc462f5072bc (patch)
treed6327eda2cbdf95b6446110014e827acccf6b8fa /client
parent5016289ac451c46299cb20542f96e2f97a7a2f1c (diff)
Fix min latency
Diffstat (limited to 'client')
-rw-r--r--client/go/internal/vespa/document/feeder.go2
-rw-r--r--client/go/internal/vespa/document/feeder_test.go34
2 files changed, 35 insertions, 1 deletions
diff --git a/client/go/internal/vespa/document/feeder.go b/client/go/internal/vespa/document/feeder.go
index e7e891a3975..6996e649d24 100644
--- a/client/go/internal/vespa/document/feeder.go
+++ b/client/go/internal/vespa/document/feeder.go
@@ -80,7 +80,7 @@ func (s *Stats) Add(other Stats) {
s.Errors += other.Errors
s.Inflight += other.Inflight
s.TotalLatency += other.TotalLatency
- if s.MinLatency == 0 || other.MinLatency < s.MinLatency {
+ if s.MinLatency == 0 || (other.MinLatency > 0 && other.MinLatency < s.MinLatency) {
s.MinLatency = other.MinLatency
}
if other.MaxLatency > s.MaxLatency {
diff --git a/client/go/internal/vespa/document/feeder_test.go b/client/go/internal/vespa/document/feeder_test.go
new file mode 100644
index 00000000000..1368d871436
--- /dev/null
+++ b/client/go/internal/vespa/document/feeder_test.go
@@ -0,0 +1,34 @@
+package document
+
+import (
+ "reflect"
+ "testing"
+ "time"
+)
+
+func TestStatsAdd(t *testing.T) {
+ got := NewStats()
+ got.Add(Stats{Requests: 1})
+ got.Add(Stats{Requests: 1})
+ got.Add(Stats{Responses: 1})
+ got.Add(Stats{Responses: 1})
+ got.Add(Stats{ResponsesByCode: map[int]int64{200: 2}})
+ got.Add(Stats{ResponsesByCode: map[int]int64{200: 2}})
+ got.Add(Stats{MinLatency: 200 * time.Millisecond})
+ got.Add(Stats{MaxLatency: 400 * time.Millisecond})
+ got.Add(Stats{MinLatency: 100 * time.Millisecond})
+ got.Add(Stats{MaxLatency: 500 * time.Millisecond})
+ got.Add(Stats{MaxLatency: 300 * time.Millisecond})
+ got.Add(Stats{})
+
+ want := Stats{
+ Requests: 2,
+ Responses: 2,
+ ResponsesByCode: map[int]int64{200: 4},
+ MinLatency: 100 * time.Millisecond,
+ MaxLatency: 500 * time.Millisecond,
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("got %+v, want %+v", got, want)
+ }
+}