1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-05 13:15:26 +02:00

test: improved tests

This commit is contained in:
Carlos Alexandro Becker 2018-07-09 22:04:25 -07:00
parent b6f6e227de
commit 8e62dddd29
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 13 additions and 6 deletions

View File

@ -1,9 +1,10 @@
// Package semerrgroup provides a small and simple semaphore lib for goreleaser.
// Package semerrgroup wraps a error group with a semaphore with configurable
// size, so you can control the number of tasks being executed simultaneously.
package semerrgroup
import "golang.org/x/sync/errgroup"
// Group is the Group itself
// Group is the Semphore ErrorGroup itself
type Group struct {
ch chan bool
g errgroup.Group
@ -19,8 +20,8 @@ func New(size int) *Group {
// Go execs one function respecting the group and semaphore.
func (s *Group) Go(fn func() error) {
s.ch <- true
s.g.Go(func() error {
s.ch <- true
defer func() {
<-s.ch
}()
@ -28,7 +29,7 @@ func (s *Group) Go(fn func() error) {
})
}
// Release releases one Group permit
// Wait waits for the group to complete and return an error if any.
func (s *Group) Wait() error {
return s.g.Wait()
}

View File

@ -1,17 +1,23 @@
package semerrgroup
import (
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestSemaphore(t *testing.T) {
var g = New(1)
var counter = 0
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
})
}