|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package syncx
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"sync"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
@ -10,11 +11,15 @@ func TestBarrier_Guard(t *testing.T) {
|
|
|
|
|
const total = 10000
|
|
|
|
|
var barrier Barrier
|
|
|
|
|
var count int
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
wg.Add(total)
|
|
|
|
|
for i := 0; i < total; i++ {
|
|
|
|
|
barrier.Guard(func() {
|
|
|
|
|
go barrier.Guard(func() {
|
|
|
|
|
count++
|
|
|
|
|
wg.Done()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
wg.Wait()
|
|
|
|
|
assert.Equal(t, total, count)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -22,10 +27,14 @@ func TestBarrierPtr_Guard(t *testing.T) {
|
|
|
|
|
const total = 10000
|
|
|
|
|
barrier := new(Barrier)
|
|
|
|
|
var count int
|
|
|
|
|
wg := new(sync.WaitGroup)
|
|
|
|
|
wg.Add(total)
|
|
|
|
|
for i := 0; i < total; i++ {
|
|
|
|
|
barrier.Guard(func() {
|
|
|
|
|
go barrier.Guard(func() {
|
|
|
|
|
count++
|
|
|
|
|
wg.Done()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
wg.Wait()
|
|
|
|
|
assert.Equal(t, total, count)
|
|
|
|
|
}
|
|
|
|
|