Skip to content

Commit

Permalink
test(expvarhandler): fix failure when using -count to run more than o…
Browse files Browse the repository at this point in the history
…nce (#1688)
  • Loading branch information
nickajacks1 committed Jan 6, 2024
1 parent 28615eb commit 08c8d32
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions expvarhandler/expvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 08c8d32

Please sign in to comment.