cleaner_test.go 955 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package cache
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/zeromicro/go-zero/core/proc"
  7. )
  8. func TestNextDelay(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. input time.Duration
  12. output time.Duration
  13. ok bool
  14. }{
  15. {
  16. name: "second",
  17. input: time.Second,
  18. output: time.Second * 5,
  19. ok: true,
  20. },
  21. {
  22. name: "5 seconds",
  23. input: time.Second * 5,
  24. output: time.Minute,
  25. ok: true,
  26. },
  27. {
  28. name: "minute",
  29. input: time.Minute,
  30. output: time.Minute * 5,
  31. ok: true,
  32. },
  33. {
  34. name: "5 minutes",
  35. input: time.Minute * 5,
  36. output: time.Hour,
  37. ok: true,
  38. },
  39. {
  40. name: "hour",
  41. input: time.Hour,
  42. output: 0,
  43. ok: false,
  44. },
  45. }
  46. for _, test := range tests {
  47. t.Run(test.name, func(t *testing.T) {
  48. next, ok := nextDelay(test.input)
  49. assert.Equal(t, test.ok, ok)
  50. assert.Equal(t, test.output, next)
  51. proc.Shutdown()
  52. })
  53. }
  54. }