Skip to content

Instantly share code, notes, and snippets.

@jeanbza
Created August 25, 2021 14:35
Show Gist options
  • Save jeanbza/e3fb0059ee4d9fc3d708b9389de0e7ee to your computer and use it in GitHub Desktop.
Save jeanbza/e3fb0059ee4d9fc3d708b9389de0e7ee to your computer and use it in GitHub Desktop.
sema_test.go
package jdksync
import (
"testing"
"time"
)
func TestItAll(t *testing.T) {
s := NewSema()
for i := 0; i < 10; i++ {
select {
case <-s.Wait():
default:
t.Fatal("should not have had to wait before calling block!")
}
s.Block()
select {
case <-s.Wait():
t.Fatal("blocked - should not have passed beyond wait")
case <-time.After(time.Second):
}
s.Unblock()
select {
case <-s.Wait():
default:
t.Fatal("should not have had to wait after calling unblock!")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment