Skip to content

Commit

Permalink
fix: zk lock ut (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLBer authored Dec 14, 2021
1 parent d1b13d5 commit eb92185
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions components/lock/zookeeper/zookeeper_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ func TestZookeeperLock_ALock_AUnlock(t *testing.T) {
lockConn := utils.NewMockZKConnection(ctrl)
factory := utils.NewMockConnectionFactory(ctrl)
path := "/" + resouseId
factory.EXPECT().NewConnection(time.Duration(expireTime)*time.Second, comp.metadata).Return(lockConn, nil).Times(2)

factory.EXPECT().NewConnection(time.Duration(expireTime)*time.Second, comp.metadata).Return(lockConn, nil).Times(1)
lockConn.EXPECT().Create(path, []byte(lockOwerA), int32(zk.FlagEphemeral), zk.WorldACL(zk.PermAll)).Return("", nil).Times(1)
lockConn.EXPECT().Close().Return().Times(1)

unlockConn.EXPECT().Get(path).Return([]byte(lockOwerA), &zk.Stat{Version: 123}, nil).Times(1)
unlockConn.EXPECT().Delete(path, int32(123)).Return(nil).Times(1)

Expand Down Expand Up @@ -92,13 +89,9 @@ func TestZookeeperLock_ALock_BUnlock(t *testing.T) {
lockConn := utils.NewMockZKConnection(ctrl)
factory := utils.NewMockConnectionFactory(ctrl)
path := "/" + resouseId
factory.EXPECT().NewConnection(time.Duration(expireTime)*time.Second, comp.metadata).Return(lockConn, nil).Times(2)

factory.EXPECT().NewConnection(time.Duration(expireTime)*time.Second, comp.metadata).Return(lockConn, nil).Times(1)
lockConn.EXPECT().Create(path, []byte(lockOwerA), int32(zk.FlagEphemeral), zk.WorldACL(zk.PermAll)).Return("", nil).Times(1)
lockConn.EXPECT().Close().Return().Times(1)

unlockConn.EXPECT().Get(path).Return([]byte(lockOwerA), &zk.Stat{Version: 123}, nil).Times(1)
unlockConn.EXPECT().Delete(path, int32(123)).Return(nil).Times(1)

comp.unlockConn = unlockConn
comp.factory = factory
Expand Down Expand Up @@ -137,12 +130,12 @@ func TestZookeeperLock_ALock_BLock_AUnlock_BLock_BUnlock(t *testing.T) {
lockConn.EXPECT().Create(path, []byte(lockOwerA), int32(zk.FlagEphemeral), zk.WorldACL(zk.PermAll)).Return("", nil).Times(1)
lockConn.EXPECT().Create(path, []byte(lockOwerB), int32(zk.FlagEphemeral), zk.WorldACL(zk.PermAll)).Return("", zk.ErrNodeExists).Times(1)
lockConn.EXPECT().Create(path, []byte(lockOwerB), int32(zk.FlagEphemeral), zk.WorldACL(zk.PermAll)).Return("", nil).Times(1)
lockConn.EXPECT().Close().Return().Times(5)
lockConn.EXPECT().Close().Return().Times(1)

unlockConn.EXPECT().Get(path).Return([]byte(lockOwerA), &zk.Stat{Version: 123}, nil).Times(1)
unlockConn.EXPECT().Get(path).Return([]byte(lockOwerB), &zk.Stat{Version: 124}, nil).Times(1)
unlockConn.EXPECT().Delete(path, int32(123)).Return(nil).Times(2)
unlockConn.EXPECT().Delete(path, int32(124)).Return(nil).Times(2)
unlockConn.EXPECT().Delete(path, int32(123)).Return(nil).Times(1)
unlockConn.EXPECT().Delete(path, int32(124)).Return(nil).Times(1)

comp.unlockConn = unlockConn
comp.factory = factory
Expand Down

0 comments on commit eb92185

Please sign in to comment.