Store and use the correct IDs in TestRemoteLocks

This commit is contained in:
James Bardin 2017-02-15 10:39:35 -05:00
parent f5ed8cd288
commit 6aa1066f7c
1 changed files with 10 additions and 12 deletions

View File

@ -65,31 +65,29 @@ func TestRemoteLocks(t *testing.T, a, b Client) {
infoB.Operation = "test" infoB.Operation = "test"
infoB.Who = "clientB" infoB.Who = "clientB"
if _, err := lockerA.Lock(infoA); err != nil { lockIDA, err := lockerA.Lock(infoA)
if err != nil {
t.Fatal("unable to get initial lock:", err) t.Fatal("unable to get initial lock:", err)
} }
if _, err := lockerB.Lock(infoB); err == nil { _, err = lockerB.Lock(infoB)
lockerA.Unlock("") if err == nil {
lockerA.Unlock(lockIDA)
t.Fatal("client B obtained lock while held by client A") t.Fatal("client B obtained lock while held by client A")
} else {
t.Log("lock info error:", err)
} }
if err := lockerA.Unlock(""); err != nil { if err := lockerA.Unlock(lockIDA); err != nil {
t.Fatal("error unlocking client A", err) t.Fatal("error unlocking client A", err)
} }
if _, err := lockerB.Lock(infoB); err != nil { lockIDB, err := lockerB.Lock(infoB)
if err != nil {
t.Fatal("unable to obtain lock from client B") t.Fatal("unable to obtain lock from client B")
} }
if err := lockerB.Unlock(""); err != nil { if err = lockerB.Unlock(lockIDB); err != nil {
t.Fatal("error unlocking client B:", err) t.Fatal("error unlocking client B:", err)
} }
// unlock should be repeatable // TODO: Should we enforce that Unlock requires the correct ID?
if err := lockerA.Unlock(""); err != nil {
t.Fatal("Unlock error from client A when state was not locked:", err)
}
} }