all: fix six tests that failed with -count=2
Avery found a bunch of tests that fail with -count=2. Updates tailscale/corp#40176 (tracks making our CI detect them) Change-Id: Ie3e4398070dd92e4fe0146badddf1254749cca20 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Co-authored-by: Avery Pennarun <apenwarr@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
13d5370951
commit
9fbe4b3ed2
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"tailscale.com/feature/buildfeatures"
|
||||
"tailscale.com/util/set"
|
||||
"tailscale.com/util/testenv"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -452,6 +453,24 @@ func (b *deltaEncBuf) writeHexVarint(v int64) {
|
||||
b.buf.Write(hexBuf)
|
||||
}
|
||||
|
||||
// ResetForTest resets all client metric values to zero.
|
||||
// It panics if not in a test or if called from a parallel test.
|
||||
func ResetForTest(t testenv.TB) {
|
||||
if !testenv.InTest() {
|
||||
panic("clientmetric.ResetForTest called outside a test")
|
||||
}
|
||||
if testenv.InParallelTest(t) {
|
||||
panic("clientmetric.ResetForTest called from a parallel test")
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
for _, m := range metrics {
|
||||
if m.v != nil {
|
||||
atomic.StoreInt64(m.v, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var TestHooks testHooks
|
||||
|
||||
type testHooks struct{}
|
||||
|
||||
@@ -30,3 +30,5 @@ func NewCounter(string) *Metric { return &zeroMetric }
|
||||
func NewGauge(string) *Metric { return &zeroMetric }
|
||||
func NewAggregateCounter(string) *Metric { return &zeroMetric }
|
||||
func NewCounterFunc(string, func() int64) *Metric { return &zeroMetric }
|
||||
|
||||
func ResetForTest(any) {}
|
||||
|
||||
Reference in New Issue
Block a user