github.phpd.cn/goreleaser/goreleaser@v0.92.0/internal/semerrgroup/sem_test.go (about) 1 package semerrgroup 2 3 import ( 4 "sync" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestSemaphore(t *testing.T) { 12 var g = New(4) 13 var lock sync.Mutex 14 var counter int 15 for i := 0; i < 10; i++ { 16 g.Go(func() error { 17 time.Sleep(10 * time.Millisecond) 18 lock.Lock() 19 counter++ 20 lock.Unlock() 21 return nil 22 }) 23 } 24 require.NoError(t, g.Wait()) 25 require.Equal(t, counter, 10) 26 }