mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-08 03:31:59 +02:00
27 lines
405 B
Go
27 lines
405 B
Go
package semerrgroup
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSemaphore(t *testing.T) {
|
|
var g = New(4)
|
|
var lock sync.Mutex
|
|
var counter int
|
|
for i := 0; i < 10; i++ {
|
|
g.Go(func() error {
|
|
time.Sleep(10 * time.Millisecond)
|
|
lock.Lock()
|
|
counter++
|
|
lock.Unlock()
|
|
return nil
|
|
})
|
|
}
|
|
require.NoError(t, g.Wait())
|
|
require.Equal(t, counter, 10)
|
|
}
|