multipusher_test.go 835 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package queue
  2. import (
  3. "fmt"
  4. "math"
  5. "strconv"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestMultiQueuePusher(t *testing.T) {
  10. const numPushers = 100
  11. var pushers []Pusher
  12. var mockedPushers []*mockedPusher
  13. for i := 0; i < numPushers; i++ {
  14. p := &mockedPusher{
  15. name: "pusher:" + strconv.Itoa(i),
  16. }
  17. pushers = append(pushers, p)
  18. mockedPushers = append(mockedPushers, p)
  19. }
  20. pusher := NewMultiPusher(pushers)
  21. assert.True(t, len(pusher.Name()) > 0)
  22. for i := 0; i < 1000; i++ {
  23. _ = pusher.Push("item")
  24. }
  25. var counts []int
  26. for _, p := range mockedPushers {
  27. counts = append(counts, p.count)
  28. }
  29. mean := calcMean(counts)
  30. variance := calcVariance(mean, counts)
  31. assert.True(t, math.Abs(mean-1000*(1-failProba)) < 10)
  32. assert.True(t, variance < 100, fmt.Sprintf("too big variance - %.2f", variance))
  33. }