batching_queue_test.go 467 B

12345678910111213141516171819202122232425
  1. package util_test
  2. import (
  3. "fmt"
  4. "heckel.io/ntfy/util"
  5. "math/rand"
  6. "testing"
  7. "time"
  8. )
  9. func TestConcurrentQueue_Next(t *testing.T) {
  10. q := util.NewBatchingQueue[int](25, 200*time.Millisecond)
  11. go func() {
  12. for batch := range q.Pop() {
  13. fmt.Printf("Batch of %d items\n", len(batch))
  14. }
  15. }()
  16. for i := 0; i < 1000; i++ {
  17. go func(i int) {
  18. time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
  19. q.Push(i)
  20. }(i)
  21. }
  22. time.Sleep(2 * time.Second)
  23. }