sheddingstat_test.go 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package load
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestSheddingStat(t *testing.T) {
  8. st := NewSheddingStat("any")
  9. for i := 0; i < 3; i++ {
  10. st.IncrementTotal()
  11. }
  12. for i := 0; i < 5; i++ {
  13. st.IncrementPass()
  14. }
  15. for i := 0; i < 7; i++ {
  16. st.IncrementDrop()
  17. }
  18. result := st.reset()
  19. assert.Equal(t, int64(3), result.Total)
  20. assert.Equal(t, int64(5), result.Pass)
  21. assert.Equal(t, int64(7), result.Drop)
  22. }
  23. func TestLoopTrue(t *testing.T) {
  24. ch := make(chan time.Time, 1)
  25. ch <- time.Now()
  26. close(ch)
  27. st := new(SheddingStat)
  28. logEnabled.Set(true)
  29. st.loop(ch)
  30. }
  31. func TestLoopTrueAndDrop(t *testing.T) {
  32. ch := make(chan time.Time, 1)
  33. ch <- time.Now()
  34. close(ch)
  35. st := new(SheddingStat)
  36. st.IncrementDrop()
  37. logEnabled.Set(true)
  38. st.loop(ch)
  39. }
  40. func TestLoopFalseAndDrop(t *testing.T) {
  41. ch := make(chan time.Time, 1)
  42. ch <- time.Now()
  43. close(ch)
  44. st := new(SheddingStat)
  45. st.IncrementDrop()
  46. logEnabled.Set(false)
  47. st.loop(ch)
  48. }