time_test.go 461 B

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