mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-14 06:01:33 -04:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user