1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

27 lines
405 B
Go
Raw Normal View History

package semerrgroup
import (
2018-07-09 22:04:25 -07:00
"sync"
"testing"
2018-07-09 22:04:25 -07:00
"time"
"github.com/stretchr/testify/require"
)
func TestSemaphore(t *testing.T) {
2018-07-09 22:04:25 -07:00
var g = New(4)
var lock sync.Mutex
var counter int
for i := 0; i < 10; i++ {
2018-07-04 01:37:32 -07:00
g.Go(func() error {
2018-07-09 22:04:25 -07:00
time.Sleep(10 * time.Millisecond)
lock.Lock()
counter++
2018-07-09 22:04:25 -07:00
lock.Unlock()
2018-07-04 01:37:32 -07:00
return nil
})
}
2018-07-04 01:37:32 -07:00
require.NoError(t, g.Wait())
require.Equal(t, counter, 10)
}