geziyor/middleware/delay_test.go
Musab Gültekin 2cab68d2ce Middlewares refactored to multiple files in middleware package.
Extractors removed as they introduce complexity to scraper. Both in learning and developing.
2019-07-04 21:04:29 +03:00

20 lines
439 B
Go

package middleware
import (
"github.com/stretchr/testify/assert"
"math/rand"
"testing"
"time"
)
func TestRandomDelay(t *testing.T) {
rand.Seed(time.Now().UnixNano())
delay := time.Millisecond * 1000
min := float64(delay) * 0.5
max := float64(delay) * 1.5
randomDelay := rand.Intn(int(max-min)) + int(min)
assert.True(t, time.Duration(randomDelay).Seconds() < 1.5)
assert.True(t, time.Duration(randomDelay).Seconds() > 0.5)
}