2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-10 13:10:26 +00:00
cointop/vendor/go4.org/syncutil/sem_test.go
2018-04-26 01:07:36 -07:00

34 lines
500 B
Go

package syncutil_test
import (
"testing"
"go4.org/syncutil"
)
func TestSem(t *testing.T) {
s := syncutil.NewSem(5)
if err := s.Acquire(2); err != nil {
t.Fatal(err)
}
if err := s.Acquire(2); err != nil {
t.Fatal(err)
}
go func() {
s.Release(2)
s.Release(2)
}()
if err := s.Acquire(5); err != nil {
t.Fatal(err)
}
}
func TestSemErr(t *testing.T) {
s := syncutil.NewSem(5)
if err := s.Acquire(6); err == nil {
t.Fatal("Didn't get expected error for large acquire.")
}
}