From 399eda676f7889accf72231c6696b89de7ea3fae Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Wed, 12 Jul 2023 11:11:10 -0400 Subject: [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 --- series/series.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'series') 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} +} -- cgit v1.2.3