aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar nickajacks1 <128185314+nickajacks1@users.noreply.github.com> 2024-01-05 21:35:20 -0800
committerGravatar GitHub <noreply@github.com> 2024-01-06 13:35:20 +0800
commit08c8d32471031b704f40832594c5fc8fba4f9db9 (patch)
treee069195d9d7c975ffedaf7fe7d213c87863cba6b
parentChange empty string checks to be more idiomatic (#1684) (diff)
downloadfasthttp-08c8d32471031b704f40832594c5fc8fba4f9db9.tar.gz
fasthttp-08c8d32471031b704f40832594c5fc8fba4f9db9.tar.bz2
fasthttp-08c8d32471031b704f40832594c5fc8fba4f9db9.zip
test(expvarhandler): fix failure when using -count to run more than once (#1688)
-rw-r--r--expvarhandler/expvar_test.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/expvarhandler/expvar_test.go b/expvarhandler/expvar_test.go
index e6114d7..6fa1d0d 100644
--- a/expvarhandler/expvar_test.go
+++ b/expvarhandler/expvar_test.go
@@ -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