From 08c8d32471031b704f40832594c5fc8fba4f9db9 Mon Sep 17 00:00:00 2001 From: nickajacks1 <128185314+nickajacks1@users.noreply.github.com> Date: Fri, 5 Jan 2024 21:35:20 -0800 Subject: test(expvarhandler): fix failure when using -count to run more than once (#1688) --- expvarhandler/expvar_test.go | 13 ++++++++++--- 1 file 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 -- cgit v1.2.3