mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
test(expvarhandler): fix failure when using -count to run more than once (#1688)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user