1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/semerrgroup/sem_test.go

27 lines
405 B
Go
Raw Normal View History

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