From 6466ef750fd627b7d91105355b5e707688ea1aab Mon Sep 17 00:00:00 2001 From: s0s01qp Date: Wed, 21 Jul 2021 13:47:13 +0530 Subject: [PATCH] added test cases and fixed lint issues --- controllers/fasthttp/commons_test.go | 10 ++++++++-- core/httptrace_test.go | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) 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 {