summaryrefslogtreecommitdiffhomepage
path: root/syncs/syncs_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'syncs/syncs_test.go')
-rw-r--r--syncs/syncs_test.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/syncs/syncs_test.go b/syncs/syncs_test.go
index 9de72e22f..a6768e90b 100644
--- a/syncs/syncs_test.go
+++ b/syncs/syncs_test.go
@@ -4,7 +4,10 @@
package syncs
-import "testing"
+import (
+ "context"
+ "testing"
+)
func TestWaitGroupChan(t *testing.T) {
wg := NewWaitGroupChan()
@@ -48,3 +51,25 @@ func TestClosedChan(t *testing.T) {
}
}
}
+
+func TestSemaphore(t *testing.T) {
+ s := NewSemaphore(2)
+ s.Acquire()
+ if !s.TryAcquire() {
+ t.Fatal("want true")
+ }
+ if s.TryAcquire() {
+ t.Fatal("want false")
+ }
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+ if s.AcquireContext(ctx) {
+ t.Fatal("want false")
+ }
+ s.Release()
+ if !s.AcquireContext(context.Background()) {
+ t.Fatal("want true")
+ }
+ s.Release()
+ s.Release()
+}