time_test.go 528 B

123456789101112131415161718192021222324
  1. package protocol_test
  2. import (
  3. "testing"
  4. "time"
  5. . "github.com/v2ray/v2ray-core/common/protocol"
  6. v2testing "github.com/v2ray/v2ray-core/testing"
  7. "github.com/v2ray/v2ray-core/testing/assert"
  8. )
  9. func TestGenerateRandomInt64InRange(t *testing.T) {
  10. v2testing.Current(t)
  11. base := time.Now().Unix()
  12. delta := 100
  13. generator := NewTimestampGenerator(Timestamp(base), delta)
  14. for i := 0; i < 100; i++ {
  15. v := int64(generator())
  16. assert.Int64(v).AtMost(base + int64(delta))
  17. assert.Int64(v).AtLeast(base - int64(delta))
  18. }
  19. }