Created
August 25, 2021 14:35
-
-
Save jeanbza/e3fb0059ee4d9fc3d708b9389de0e7ee to your computer and use it in GitHub Desktop.
sema_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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