From 6f49639f80f9476ba8266bb15a1fa405460d14ce Mon Sep 17 00:00:00 2001 From: codingfanlt Date: Tue, 13 Oct 2020 19:29:20 +0800 Subject: [PATCH] fix syncx/barrier test case (#123) --- core/syncx/barrier_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/syncx/barrier_test.go b/core/syncx/barrier_test.go index c763f1b3..95cb7574 100644 --- a/core/syncx/barrier_test.go +++ b/core/syncx/barrier_test.go @@ -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) }