barrier_test.go 491 B

12345678910111213141516171819202122232425262728293031
  1. package syncx
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestBarrier_Guard(t *testing.T) {
  7. const total = 10000
  8. var barrier Barrier
  9. var count int
  10. for i := 0; i < total; i++ {
  11. barrier.Guard(func() {
  12. count++
  13. })
  14. }
  15. assert.Equal(t, total, count)
  16. }
  17. func TestBarrierPtr_Guard(t *testing.T) {
  18. const total = 10000
  19. barrier := new(Barrier)
  20. var count int
  21. for i := 0; i < total; i++ {
  22. barrier.Guard(func() {
  23. count++
  24. })
  25. }
  26. assert.Equal(t, total, count)
  27. }