diff --git a/controllers/fasthttp/commons_test.go b/controllers/fasthttp/commons_test.go index f81ceb0..de62002 100644 --- a/controllers/fasthttp/commons_test.go +++ b/controllers/fasthttp/commons_test.go @@ -9,16 +9,22 @@ import ( "github.com/sinhashubham95/go-actuator/models" "github.com/stretchr/testify/assert" "github.com/valyala/fasthttp" - "math/rand" "net/http" + "sync" "testing" ) var encodeJSON = commons.EncodeJSON var getThreadDump = core.GetThreadDump +var portMu sync.Mutex +var port = 1001 + func getRandomPortNumber() int { - return rand.Intn(9800) + 100 + portMu.Lock() + defer portMu.Unlock() + port += 10 + return port } func setupFastHTTPHandlersAndGetResponse(t *testing.T, endpoint int, path string) *http.Response { diff --git a/core/httptrace_test.go b/core/httptrace_test.go index d7f6592..94be7a1 100644 --- a/core/httptrace_test.go +++ b/core/httptrace_test.go @@ -8,14 +8,17 @@ import ( "github.com/sinhashubham95/go-actuator/models" "github.com/stretchr/testify/assert" "github.com/valyala/fasthttp" - "math/rand" "net/http" "net/http/httptest" + "sync" "testing" "github.com/sinhashubham95/go-actuator/core" ) +var portMu sync.Mutex +var port = 2001 + func TestGetHTTPTrace(t *testing.T) { assert.Empty(t, core.GetHTTPTrace()) } @@ -104,7 +107,10 @@ func TestForMoreThanThresholdRequests(t *testing.T) { } func getRandomPortNumber() int { - return rand.Intn(9800) + 100 + portMu.Lock() + defer portMu.Unlock() + port += 10 + return port } func setupGINRouter() *gin.Engine {