Skip to content

Commit

Permalink
Fix test error: metrics AlreadyRegisteredError
Browse files Browse the repository at this point in the history
  • Loading branch information
CatherineF-dev committed Oct 21, 2021
1 parent dcb9f8f commit 826123b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/util/flowcontrol/metrics/sample_and_watermark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package metrics
import (
"fmt"
"math/rand"
"sync"
"testing"
"time"

Expand All @@ -36,6 +37,8 @@ const (
numIterations = 100
)

var once sync.Once

/* TestSampler does a rough behavioral test of the sampling in a
SampleAndWatermarkHistograms. The test creates one and exercises
it, checking that the count in the sampling histogram is correct at
Expand All @@ -61,7 +64,9 @@ func TestSampler(t *testing.T) {
saw := gen.Generate(0, 1, []string{})
regs := gen.metrics()
for _, reg := range regs {
legacyregistry.MustRegister(reg)
once.Do(func() {
legacyregistry.MustRegister(reg)
})
}
// `dt` is the admitted cumulative difference in fake time
// since the start of the test. "admitted" means this is
Expand Down

0 comments on commit 826123b

Please sign in to comment.