test(expvarhandler): fix failure when using -count to run more than once (#1688)

This commit is contained in:
nickajacks1
2024-01-05 21:35:20 -08:00
committed by GitHub
parent 28615eba55
commit 08c8d32471
+10 -3
View File
@@ -4,17 +4,24 @@ import (
"encoding/json"
"expvar"
"strings"
"sync"
"testing"
"github.com/valyala/fasthttp"
)
var once sync.Once
func TestExpvarHandlerBasic(t *testing.T) {
t.Parallel()
expvar.Publish("customVar", expvar.Func(func() any {
return "foobar"
}))
// Publish panics if the same var is published more than once,
// which can happen if the test is run with -count
once.Do(func() {
expvar.Publish("customVar", expvar.Func(func() any {
return "foobar"
}))
})
var ctx fasthttp.RequestCtx