Skip to content

Commit

Permalink
fix: repeated tests failing when generating random limits
Browse files Browse the repository at this point in the history
  • Loading branch information
luk3skyw4lker committed Jul 11, 2024
1 parent 9e008c8 commit d7e28f4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions middleware/limiter/limiter_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package limiter

import (
"crypto/rand"
"io"
"math/big"
"net/http/httptest"
"sync"
"testing"
Expand Down Expand Up @@ -60,13 +58,11 @@ func Test_Limiter_With_Max_Calculator_With_Zero(t *testing.T) {
func Test_Limiter_With_Max_Calculator(t *testing.T) {
t.Parallel()
app := fiber.New()
max, err := rand.Int(rand.Reader, big.NewInt(10))

require.NoError(t, err)
max := 10

app.Use(New(Config{
MaxCalculator: func(_ fiber.Ctx) int {
return int(max.Int64())
return max
},
Expiration: 2 * time.Second,
Storage: memory.New(),
Expand All @@ -78,7 +74,7 @@ func Test_Limiter_With_Max_Calculator(t *testing.T) {

var wg sync.WaitGroup

for i := 0; i <= int(max.Int64())-1; i++ {
for i := 0; i <= max-1; i++ {
wg.Add(1)
go func(wg *sync.WaitGroup) {
defer wg.Done()
Expand Down

0 comments on commit d7e28f4

Please sign in to comment.