Rainbond/vendor/github.com/yudai/umutex/umutex_test.go
2017-11-20 18:12:53 +08:00

51 lines
577 B
Go

package umutex
import (
"sync"
"testing"
)
func TestTryLock(t *testing.T) {
var result bool
mutex := New()
result = mutex.TryLock()
if result != true {
t.Error()
}
result = mutex.TryLock()
if result != false {
t.Error()
}
mutex.Unlock()
result = mutex.TryLock()
if result != true {
t.Error()
}
}
func TestForceLock(t *testing.T) {
var result bool
mutex := New()
result = mutex.TryLock()
if result != true {
t.Error()
}
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
mutex.ForceLock()
}()
mutex.Unlock()
wg.Wait()
}