jitter_test.go 488 B

12345678910111213141516171819202122
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package tstime
  4. import (
  5. "testing"
  6. "time"
  7. )
  8. func TestRandomDurationBetween(t *testing.T) {
  9. if got := RandomDurationBetween(1, 1); got != 1 {
  10. t.Errorf("between 1 and 1 = %v; want 1", int64(got))
  11. }
  12. const min = 1 * time.Second
  13. const max = 10 * time.Second
  14. for range 500 {
  15. if got := RandomDurationBetween(min, max); got < min || got >= max {
  16. t.Fatalf("%v (%d) out of range", got, got)
  17. }
  18. }
  19. }