Skip to content

Commit

Permalink
Update trylock_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
subchen authored May 29, 2018
1 parent 6e9f3dd commit 318e27f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions trylock_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package trylock

import (
"sync/atomic"
"testing"
"time"
)
Expand Down Expand Up @@ -143,3 +144,25 @@ func TestMutexLockUnLockInvalid(t *testing.T) {
}()
mu.RUnlock()
}

func TestMutexLockBroadcast(t *testing.T) {
mu := New()
mu.Lock()

done := int32(0)
for i := 0; i < 3; i++ {
go func() {
mu.RLock()
atomic.AddInt32(&done, 1)
mu.RUnlock()
}()
}

mu.Unlock()

time.Sleep(10 * time.Millisecond)

if done != 3 {
t.Fatal("Broadcast is failed")
}
}

0 comments on commit 318e27f

Please sign in to comment.