From 67bbebce08ec168fc2aa9d024cbcce12f1c4bf9b Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 15 Feb 2017 12:02:37 -0500 Subject: [PATCH] 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. --- backend/remote-state/consul/client.go | 7 ++++--- state/remote/testing.go | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/remote-state/consul/client.go b/backend/remote-state/consul/client.go index a5578a3c1..8b4ed6e7e 100644 --- a/backend/remote-state/consul/client.go +++ b/backend/remote-state/consul/client.go @@ -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 } diff --git a/state/remote/testing.go b/state/remote/testing.go index bd71aefcb..b379b509d 100644 --- a/state/remote/testing.go +++ b/state/remote/testing.go @@ -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) }