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 (valyala#1688)
  • Loading branch information
nickajacks1 authored and Max-Cheng committed Feb 12, 2024
1 parent 89f0aff commit c7f3f2b
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 c7f3f2b

Please sign in to comment.