1 Star 0 Fork 4

薛定谔的猫箱 / distlock

forked from go-locks / distlock 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
distlock_test.go 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
letsfire 提交于 2019-01-26 09:43 . first Alpha version
package distlock
import (
"testing"
"github.com/go-locks/distlock/driver/mocks"
"github.com/stretchr/testify/mock"
)
var dl = mockDistlock()
func mockDistlock() *Distlock {
var mockDriver = mocks.New()
var notifyChan = make(chan struct{})
mockDriver.On("Watch", mock.Anything).Return(notifyChan)
return New(mockDriver, Prefix("test"))
}
func TestDistlock_NewMutex(t *testing.T) {
name := "mutex"
if mtx1, err := dl.NewMutex(name); err != nil {
t.Error(err)
} else if mtx2, _ := dl.NewMutex(name); mtx1 != mtx2 {
t.Error("unexpected result, mutex must be same when the name is same")
} else if _, err := dl.NewRWMutex(name); err == nil {
t.Error("unexpected result, rwmutex can not have the same name with mutex")
}
}
func TestDistlock_NewRWMutex(t *testing.T) {
name := "rwmutex"
if rwMtx1, err := dl.NewRWMutex(name); err != nil {
t.Error(err)
} else if rwMtx2, _ := dl.NewRWMutex(name); rwMtx1 != rwMtx2 {
t.Error("unexpected result, rw mutex must be same when the name is same")
} else if _, err := dl.NewMutex(name); err == nil {
t.Error("unexpected result, mutex can not have the same name with rwmutex")
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/prt53461347475/distlock.git
git@gitee.com:prt53461347475/distlock.git
prt53461347475
distlock
distlock
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891