diff options
| author | Naman Sood <mail@nsood.in> | 2021-03-29 14:28:08 -0400 |
|---|---|---|
| committer | Naman Sood <mail@nsood.in> | 2021-03-29 14:28:08 -0400 |
| commit | c0a88a0129ebf0f9886b93b1f4e4f04a7c3bb86f (patch) | |
| tree | 57d5aef2985e3424e5bb6f4c810628aa3ccbf5d0 /syncs/syncs_test.go | |
| parent | 47bd3c4cf5543fd7ecb049302c37c1001fa9f2d6 (diff) | |
| parent | a4c679e64691a3f0ba41ad9078312ca67e5e67fd (diff) | |
| download | tailscale-naman/netstack-subnet-routing.tar.xz tailscale-naman/netstack-subnet-routing.zip | |
merge with mainnaman/netstack-subnet-routing
Signed-off-by: Naman Sood <mail@nsood.in>
Diffstat (limited to 'syncs/syncs_test.go')
| -rw-r--r-- | syncs/syncs_test.go | 27 |
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() +} |
