1
0
mirror of https://github.com/tmrts/go-patterns.git synced 2024-11-22 13:06:09 +03:00
go-patterns/semaphore/semaphore_test.go
2016-02-20 17:32:46 +02:00

31 lines
697 B
Go

package semaphore_test
import (
"testing"
"time"
"github.com/tmrts/go-patterns/semaphore"
)
func TestCreatesSemaphore(t *testing.T) {
tickets, timeout := 1, 3*time.Second
s := semaphore.New(tickets, timeout)
if err := s.Acquire(); err != nil {
t.Errorf("semaphore.Acquire() got errors %s", err)
}
if err := s.Release(); err != nil {
t.Errorf("semaphore.Release() got errors %s", err)
}
}
func TestCreatesNonBlockingSemaphore(t *testing.T) {
tickets, timeout := 0, 0
s := semaphore.New(tickets, timeout)
if err := s.Acquire(); err != semaphore.ErrIllegalRelease {
t.Errorf("non-blocking semaphore.Acquire() expected error %s got %s", semaphore.ErrIllegalRelease, err)
}
}