summaryrefslogtreecommitdiff
path: root/series/series.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2023-07-12 11:11:10 -0400
committerWill Hawkins <[email protected]>2023-07-12 11:11:10 -0400
commit399eda676f7889accf72231c6696b89de7ea3fae (patch)
treeddbe2afa4ef2a1e28b9a8b36577832b12a74b138 /series/series.go
parent06fd8c3b39979316ec8917d471416114a5b7c581 (diff)
[Bugfix] Duplicate bucket IDs caused incorrect results
The upload direction reused bucket IDs used during the test in the download direction which caused an incorrect grand-total RPM calculation. To solve the problem, this patch adds a global bucket ID generator and passes that to everyone that needs it. TODO: Make the bucket generator type more generic. Signed-off-by: Will Hawkins <[email protected]>
Diffstat (limited to 'series/series.go')
-rw-r--r--series/series.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/series/series.go b/series/series.go
index 0084007..43d9809 100644
--- a/series/series.go
+++ b/series/series.go
@@ -15,6 +15,7 @@ package series
import (
"fmt"
+ "sync"
"github.com/network-quality/goresponsiveness/utilities"
"golang.org/x/exp/constraints"
@@ -278,3 +279,20 @@ func NewWindowSeries[Data any, Bucket constraints.Ordered](tipe WindowSeriesDura
}
panic("")
}
+
+type NumericBucketGenerator[T utilities.Number] struct {
+ mt sync.Mutex
+ currentValue T
+}
+
+func (bg *NumericBucketGenerator[T]) Generate() T {
+ bg.mt.Lock()
+ defer bg.mt.Unlock()
+
+ bg.currentValue++
+ return bg.currentValue
+}
+
+func NewNumericBucketGenerator[T utilities.Number](initialValue T) NumericBucketGenerator[T] {
+ return NumericBucketGenerator[T]{currentValue: initialValue}
+}