Have consul state reutrn the lock ID

The lock ID isn't used because the lock is tied to the client, but
return the lock ID to match the behavior of other locks.
This commit is contained in:
James Bardin 2017-02-15 12:02:37 -05:00
parent f2e496a14c
commit 67bbebce08
2 changed files with 8 additions and 3 deletions

View File

@ -120,7 +120,7 @@ func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) {
lock, err := c.Client.LockOpts(opts)
if err != nil {
return "", nil
return "", err
}
c.consulLock = lock
@ -143,14 +143,15 @@ func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) {
err = c.putLockInfo(info)
if err != nil {
err = multierror.Append(err, c.Unlock(""))
err = multierror.Append(err, c.Unlock(info.ID))
return "", err
}
return "", nil
return info.ID, nil
}
func (c *RemoteClient) Unlock(id string) error {
// this doesn't use the lock id, because the lock is tied to the consul client.
if c.consulLock == nil || c.lockCh == nil {
return nil
}

View File

@ -85,6 +85,10 @@ func TestRemoteLocks(t *testing.T, a, b Client) {
t.Fatal("unable to obtain lock from client B")
}
if lockIDB == lockIDA {
t.Fatalf("duplicate lock IDs: %q", lockIDB)
}
if err = lockerB.Unlock(lockIDB); err != nil {
t.Fatal("error unlocking client B:", err)
}