time_test.go 459 B

123456789101112131415161718192021
  1. package protocol_test
  2. import (
  3. "testing"
  4. "time"
  5. . "github.com/xtls/xray-core/common/protocol"
  6. )
  7. func TestGenerateRandomInt64InRange(t *testing.T) {
  8. base := time.Now().Unix()
  9. delta := 100
  10. generator := NewTimestampGenerator(Timestamp(base), delta)
  11. for i := 0; i < 100; i++ {
  12. val := int64(generator())
  13. if val > base+int64(delta) || val < base-int64(delta) {
  14. t.Error(val, " not between ", base-int64(delta), " and ", base+int64(delta))
  15. }
  16. }
  17. }