fix syncx/barrier test case (#123)

master
codingfanlt 4 years ago committed by GitHub
parent 7d4a548d29
commit 6f49639f80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save