make state test pass with new state.Locker

This commit is contained in:
James Bardin 2017-02-14 19:00:36 -05:00
parent 4f0c465187
commit 52b2343672
2 changed files with 14 additions and 10 deletions

View File

@ -20,14 +20,17 @@ func TestLocalStateLocks(t *testing.T) {
defer os.Remove(s.Path)
// lock first
if err := s.Lock("test"); err != nil {
info := &LockInfo{
Operation: "test",
}
lockID, err := s.Lock(info)
if err != nil {
t.Fatal(err)
}
out, err := exec.Command("go", "run", "testdata/lockstate.go", s.Path).CombinedOutput()
if err != nil {
t.Fatal("unexpected lock failure", err)
t.Fatal("unexpected lock failure", err, string(out))
}
if string(out) != "lock failed" {
@ -40,25 +43,26 @@ func TestLocalStateLocks(t *testing.T) {
t.Fatal(err)
}
if lockInfo.Info != "test" {
if lockInfo.Operation != "test" {
t.Fatalf("invalid lock info %#v\n", lockInfo)
}
// a noop, since we unlock on exit
if err := s.Unlock(); err != nil {
if err := s.Unlock(lockID); err != nil {
t.Fatal(err)
}
// local locks can re-lock
if err := s.Lock("test"); err != nil {
lockID, err = s.Lock(info)
if err != nil {
t.Fatal(err)
}
// Unlock should be repeatable
if err := s.Unlock(); err != nil {
if err := s.Unlock(lockID); err != nil {
t.Fatal(err)
}
if err := s.Unlock(); err != nil {
if err := s.Unlock(lockID); err != nil {
t.Fatal(err)
}
@ -67,7 +71,6 @@ func TestLocalStateLocks(t *testing.T) {
if _, err := os.Stat(lockInfoPath); !os.IsNotExist(err) {
t.Fatal("lock info not removed")
}
}
func TestLocalState_pathOut(t *testing.T) {

View File

@ -19,10 +19,11 @@ func main() {
Path: os.Args[1],
}
err := s.Lock("test")
_, err := s.Lock(&state.LockInfo{Operation: "test", Info: "state locker"})
if err != nil {
io.WriteString(os.Stderr, "lock failed")
}
return
}