2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-06 21:20:34 +00:00
cointop/vendor/go4.org/syncutil/sem_test.go

34 lines
500 B
Go
Raw Normal View History

2018-04-26 08:07:36 +00:00
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.")
}
}