backoffs_test.go 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package retrier
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. func TestConstantBackoff(t *testing.T) {
  7. b := ConstantBackoff(1, 10*time.Millisecond)
  8. if len(b) != 1 {
  9. t.Error("incorrect length")
  10. }
  11. for i := range b {
  12. if b[i] != 10*time.Millisecond {
  13. t.Error("incorrect value at", i)
  14. }
  15. }
  16. b = ConstantBackoff(10, 250*time.Hour)
  17. if len(b) != 10 {
  18. t.Error("incorrect length")
  19. }
  20. for i := range b {
  21. if b[i] != 250*time.Hour {
  22. t.Error("incorrect value at", i)
  23. }
  24. }
  25. }
  26. func TestExponentialBackoff(t *testing.T) {
  27. b := ExponentialBackoff(1, 10*time.Millisecond)
  28. if len(b) != 1 {
  29. t.Error("incorrect length")
  30. }
  31. if b[0] != 10*time.Millisecond {
  32. t.Error("incorrect value")
  33. }
  34. b = ExponentialBackoff(4, 1*time.Minute)
  35. if len(b) != 4 {
  36. t.Error("incorrect length")
  37. }
  38. if b[0] != 1*time.Minute {
  39. t.Error("incorrect value")
  40. }
  41. if b[1] != 2*time.Minute {
  42. t.Error("incorrect value")
  43. }
  44. if b[2] != 4*time.Minute {
  45. t.Error("incorrect value")
  46. }
  47. if b[3] != 8*time.Minute {
  48. t.Error("incorrect value")
  49. }
  50. }