mirror of
https://github.com/tailscale/tailscale.git
synced 2025-09-21 13:41:46 +02:00
util/expvarx: deflake TestSafeFuncHappyPath with synctest
I probably could've deflaked this without synctest, but might as well use it now that Go 1.25 has it. Fixes #15348 Change-Id: I81c9253fcb7eada079f3e943ab5f1e29ba8e8e31 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
14adf5b717
commit
1cb855fb36
@ -9,9 +9,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
"testing/synctest"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tailscale.com/cmd/testwrapper/flakytest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleNewSafeFunc() {
|
func ExampleNewSafeFunc() {
|
||||||
@ -54,19 +53,21 @@ func ExampleNewSafeFunc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSafeFuncHappyPath(t *testing.T) {
|
func TestSafeFuncHappyPath(t *testing.T) {
|
||||||
flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/15348")
|
synctest.Test(t, func(t *testing.T) {
|
||||||
var count int
|
var count int
|
||||||
f := NewSafeFunc(expvar.Func(func() any {
|
f := NewSafeFunc(expvar.Func(func() any {
|
||||||
count++
|
count++
|
||||||
return count
|
return count
|
||||||
}), time.Millisecond, nil)
|
}), time.Second, nil)
|
||||||
|
|
||||||
if got, want := f.Value(), 1; got != want {
|
if got, want := f.Value(), 1; got != want {
|
||||||
t.Errorf("got %v, want %v", got, want)
|
t.Errorf("got %v, want %v", got, want)
|
||||||
}
|
}
|
||||||
|
time.Sleep(5 * time.Second) // (fake time in synctest)
|
||||||
if got, want := f.Value(), 2; got != want {
|
if got, want := f.Value(), 2; got != want {
|
||||||
t.Errorf("got %v, want %v", got, want)
|
t.Errorf("got %v, want %v", got, want)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSafeFuncSlow(t *testing.T) {
|
func TestSafeFuncSlow(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user